Skip to content

Disallow calling abstract methods directly on interfaces #16319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 22 commits into from
Closed

Disallow calling abstract methods directly on interfaces #16319

wants to merge 22 commits into from

Conversation

edgarfgp
Copy link
Contributor

@edgarfgp edgarfgp commented Nov 21, 2023

Fixes #14012

  • Check introduced to ensure we can call on virtual members, can't call abstracts.
open System.Numerics
IAdditionOperators.op_Addition (3, 6) // New compiler error as this is an static abstract

IAdditionOperators.op_CheckedAddition (3, 6) // Compiles and run as this a static virtual

See:
https://source.dot.net/#System.Private.CoreLib/src/libraries/System.Private.CoreLib/src/System/Numerics/IAdditionOperators.cs,5b77e6b404819054

@edgarfgp edgarfgp changed the title Disallow calling methods-directly on interfaces Disallow calling methods directly on interfaces Nov 21, 2023
@edgarfgp edgarfgp changed the title Disallow calling methods directly on interfaces Disallow calling abstract methods directly on interfaces Nov 23, 2023
@edgarfgp edgarfgp marked this pull request as ready for review November 23, 2023 16:05
@edgarfgp edgarfgp requested a review from a team as a code owner November 23, 2023 16:05
Comment on lines 923 to 926
|> shouldFail
|> withDiagnostics [
(Error 3861, Line 13, Col 71, Line 13, Col 79, "Interfaces cannot access static abstract members directly.")
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not right, constrained calls 'T.Parse should work through multiple levels of inheritance, since it will know specific implementation at runtime. ISpanParsable<'T>.Parse, if it's non-virtual, shouldn't on other hand.

@vzarytovskii
Copy link
Member

Thanks for changing it @edgarfgp, do you think it makes sense to just filter those out as non-valid methods or is it just me? It's a quite unique and new situation, since we don't really have it for non-statics.

@vzarytovskii
Copy link
Member

vzarytovskii commented Nov 25, 2023

Also, a reminder for myself for Monday: test that we still have autocomplete on type constrained call, e.g. 'T.<autocompletes all abstract methods>.

@edgarfgp
Copy link
Contributor Author

Thanks for changing it @edgarfgp, do you think it makes sense to just filter those out as non-valid methods or is it just me? It's a quite unique and new situation, since we don't really have it for non-statics.

I think the static nature of this methods will raise the expectation of been available through competition in a type tbh and it that case a dedicated error message explaining the reasoning of this behaviour will be desirable. That being said in this PR my main focus is to prevent the runtime errors currently happening.

@edgarfgp
Copy link
Contributor Author

Also, a reminder for myself for Monday: test that we still have autocomplete on type constrained call, e.g. 'T.<autocompletes all abstract methods>.

Could you also check the filtering condition please. I haven’t found yet a way to make this test pass.

@vzarytovskii
Copy link
Member

Thanks for changing it @edgarfgp, do you think it makes sense to just filter those out as non-valid methods or is it just me? It's a quite unique and new situation, since we don't really have it for non-statics.

I think the static nature of this methods will raise the expectation of been available through competition in a type tbh and it that case a dedicated error message explaining the reasoning of this behaviour will be desirable. That being said in this PR my main focus is to prevent the runtime errors currently happening.

Do we really want for it to be available via completion, it it will lead to the compile time error? I.e. not usable if it's non-virtual?

@edgarfgp edgarfgp marked this pull request as draft December 3, 2023 13:13
@edgarfgp edgarfgp closed this Dec 6, 2023
@edgarfgp edgarfgp reopened this Feb 27, 2024
Copy link
Contributor

github-actions bot commented Feb 27, 2024

❗ Release notes required


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/8.0.300.md

@edgarfgp
Copy link
Contributor Author

Replaced by #17021

@edgarfgp edgarfgp closed this Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bad image when calling op_Addition on interface
3 participants