-
Notifications
You must be signed in to change notification settings - Fork 795
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
Fix virtual static call #17013
Fix virtual static call #17013
Conversation
❗ Release notes required
|
What was the behaviour before? This needs SRTP tests as well. Also need to make sure RFC for IWSAMs mentions virtual members as well. |
@vzarytovskii ... It compiles the method invocation however it invokes the base class method implementation and not the overridden version. static virtual members are confusingly necessary for the INumerics stuff because of generics. It's a good change. |
It's a breaking change then? What do we do in case of non-statics? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change is a good one, we need to consider the breaking change. Although my intuition is that it is rare enough and breaks an important dotnet feature so we would take the break.
Although ... the scenario to implement the INumerics, may not have been a goal, I wasn't involved in those design discussions.
tests/FSharp.Compiler.ComponentTests/Interop/StaticsInInterfaces.fs
Outdated
Show resolved
Hide resolved
@vzarytovskii interfaces with virtual statics was implemented as part of the INumerics feature. We handle abstract/virtuals/override on instance methods compatibly with C#. I think we probably consume, the framework INumber implementations correctly. This particular bug is likely merely an oversight. |
Oh yeah, and there is no real performance implications. |
I know, I implemented those in F#. Question is which method do we call now A should match B. |
For virtual inheritence, it should be the most derived. Static should emulate that I should think. |
The prior behaviour was the override of a virtual static method could not be called by F#. Just a note that SRTP cannot be used to call the override of Regarding the RFC, are you referring to RFC FS-1124, this does not mention virtual static methods.
The overridden method is called: [<FactForNETCOREAPP>]
let ``F# can call overwritten virtual member from interface``() =
let CSharpLib =
CSharp """
namespace Test;
public interface I
{
virtual string Echo(string x) => $"I.Echo: {x}";
}
"""
|> withCSharpLanguageVersion CSharpLanguageVersion.CSharp11
|> withName "CsLibAssembly"
FSharp """
type Imp() =
interface Test.I with
member _.Echo (x: string) = $"Imp.I.Echo: {x}"
let echo<'T when 'T :> Test.I> (a: 'T) x = a.Echo(x)
match echo (Imp()) "a" with
| "Imp.I.Echo: a" -> printfn "success"
| _ -> failwith "incorrect value"
"""
|> withReferences [CSharpLib]
|> withLangVersion80
|> asExe
|> compileAndRun
|> shouldSucceed
I agree :-). Currently we: Thus, this change is required to bring A and B into alignment. |
Out of interest, what is the protocol for resolving comments? Should I do it once I made the appropriate change/comment, or does the commenter resolve it once satisfied? |
Yeah, this one. Probably then add a one-liner saying what will be preferred in case of virtual methods. |
I've created fsharp/fslang-design#766 |
Feel free to resolve if you've addressed it |
Required for IL comparison.
Thanks @DragonSA and to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks
Absolutely, thanks for sponsoring ❤️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Head branch was pushed to by a user without write access
Description
Fix calling an overridden virtual static method via the interface.
The current fsharp calls, ends up calling the default implementation of C# static virtual methods. This fixes this by ensuring that the static virtual metadata is honoured in method resolution.
Checklist
Sponsorship
Counterpoint Dynamics (Pty) Ltd