-
Notifications
You must be signed in to change notification settings - Fork 802
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
[VS 2017 RC - From VSTS] C#-style extension method fails to compile #1802
Comments
@cartermp This seems like a C# compiler regression: I don't think F# is doing anything different here. Does adding the |
@jaredpar for FYI. I'm looking to repro on my machine, but Parallels seems to be stalled on an update and I don't have a Windows machine nearby. |
There needs to be an assembly level attribute as well. This is a known change that came in the Roslyn 1.0 timeframe. |
@jaredpar I thought the decision was to fix that in C#? Anyway there's a relevant old issue here: http://visualfsharp.codeplex.com/workitem/76 |
Specifcally:
But then this:
|
@jaredpar Perhaps the "F#-specific hack" is no longer working? |
just for notice, the assembly level attribute has always been required for the call to work in VB.NET. I had this comment on another issue: #1254 (comment)
|
@dsyme |
Is emitting the warning any easier than actually putting the attribute implicitly? C# and VB.NET don't have to state the attribute explicitly as the compiler will add it to the class(es) and assembly whenever an extension method is found. |
+1 for adding the attribute if that's possible. |
Could you please provide the actual repro steps? |
@AlekseyTs The text of the bug report is from VSTS generated from here: https://developercommunity.visualstudio.com/content/problem/3246/c-extension-methods-written-in-f-can-no-longer-be.html I can't seem to find the attached solution which repros this - I'll try something on my machine. |
@cartermp, @AlekseyTs I'm the one who wrote up the VSTS bug report being quoted, and I can say with certainty that adding the assembly-level ExtensionAttribute does not help. It seems to have more to do with resolving generic parameters than what attributes are present. Here's the repro solution I had attached to the VSTS bug report. You can build that code in VS 2015, but not in VS 2017 RC, and the assembly-level Extension attribute is present. |
@jaredpar maybe C# team should take a look as well. |
@forki @AlekseyTs is on the C# team. |
Good. Thx |
It looks like the C# compiler error is caused by a behavior change in F# compiler. Here is how the extension methods look like when compiled in VS2015:
And this is how they look when compiled by VS2017:
C# compiler is unable to infer the last type parameter because it is not used in any of the parameters. BTW, the IL of the generic methods looks suspicious to me as well. |
@dsyme, @cartermp based on @AlekseyTs analysis this seems like a regression in the F# compiler. Are you all seeing the same output? |
Yep, getting the same output on my machine as well. Seems like a regression to me. @KevinRansom for FYI. |
@cartermp @jaredpar Yes, this is a known-change-of-behavior. Whether we should keep the new behavior ("Extensions are in scope within their own definition") or try to revert to the old behavior needs to be decided. Analysis is the same as this: #1296 (comment) |
@dsyme I'm of the opinion that we ought to revert to the old behavior. We don't have any numbers on usage, but this does seem like a tricky breaking change.
Is there a fix on hand? We're fast-approaching code freeze, so if we're not able to get something in then we'll need to message the fact that the F# 4.1 compiler has this breaking change. |
@cartermp I will search for a fix if I can find time (in theory am still on vacation). However will be very subtle, so we should be prepared for this to be a breaking change (justified as a bug fix). To my knowledge it would be the first time we've taken such a fix intentionally. |
Sounds good. |
Tagging as RTM - this will be resolved either via fix or notifying that F# 4.1 includes this breaking change. |
@cartermp This can now be resolved as by-design |
Okay. We'll take note of this in the blog post when we announce F# 4.1 |
@cartermp, I think this is a something for C# to state as F# didn't change behaviour while C# did, VB.NET has same limitation since day 1 and requires explicit attribute on the assembly as well. What we should announce in future is that the attribute is automatically added by compiler like VB & C# are doing 😃 |
@smoothdeveloper This issue is about a change in F# behavior as explained here #1802 (comment). |
@AlekseyTs I see, thanks I thought the notice of change was about the code in the issue itself. I actually don't understand how the code became generic in new F# as only this overload could match: https://msdn.microsoft.com/en-us/library/t4411bks(v=vs.110).aspx |
for now i see a "workaround" is to use (in C#) this makes the extension method usable in C# side. |
FROM VSTS:
Take an extension method written in F# for consumption by C#. Note that this is not using F#-style extension methods, it's using the same attributes that have been implicitly inserted by the C# compiler in previous versions when writing extension methods in C#.
Use that extension method in some C# code.
That sort of code has compiled without error since at least VS 2012, and now without any changes, in VS 2017 RC it's getting this compiler error:
Note that the above code is a rough illustration, and doesn't actually reproduce the error. I'm attaching a stand-alone minimal repro case that does reproduce the compiler error.
The text was updated successfully, but these errors were encountered: