You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if(resolution.IsExtensionMethodGroup)// Tracked by https://github.com/dotnet/roslyn/issues/78960 : we need to handle new extension methods
1486
+
if(resolution.IsExtensionMethodGroup)
1475
1487
{
1476
1488
// We need to validate an ability to infer type arguments as well as check conversion to 'this' parameter.
1477
1489
// Overload resolution doesn't check the conversion when 'this' type refers to a type parameter
// Otherwise, there were no dynamic arguments and overload resolution found a unique best candidate.
1603
-
// We still have to determine if it passes final validation.
1604
-
1605
-
varmethodResult=result.ValidResult;
1606
-
varmethod=methodResult.Member;
1607
-
1608
-
// Tracked by https://github.com/dotnet/roslyn/issues/78960: It looks like we added a bunch of code in BindInvocationExpressionContinued at this position
1609
-
// that specifically deals with new extension methods. It adjusts analyzedArguments, etc.
1610
-
// It is very likely we need to do the same here.
1611
-
1612
-
// It is possible that overload resolution succeeded, but we have chosen an
1613
-
// instance method and we're in a static method. A careful reading of the
1614
-
// overload resolution spec shows that the "final validation" stage allows an
1615
-
// "implicit this" on any method call, not just method calls from inside
1616
-
// instance methods. Therefore we must detect this scenario here, rather than in
1617
-
// overload resolution.
1618
-
1619
-
varreceiver=methodGroup.Receiver;
1620
-
1621
-
// Note: we specifically want to do final validation (7.6.5.1) without checking delegate compatibility (15.2),
1622
-
// so we're calling MethodGroupFinalValidation directly, rather than via MethodGroupConversionHasErrors.
1623
-
// Note: final validation wants the receiver that corresponds to the source representation
1624
-
// (i.e. the first argument, if invokedAsExtensionMethod).
// Add methods. This case can be hit for spreads and non-spread elements.
1669
1649
Debug.Assert(call.HasErrors);
1670
1650
Debug.Assert(call.Method.Name=="Add");
1671
-
returncall.Arguments[call.InvokedAsExtensionMethod?1:0];// Tracked by https://github.com/dotnet/roslyn/issues/78960: Add test coverage for new extensions
Debug.Assert(allowAlpha||!from.Any(static tp =>tpisSubstitutedTypeParameterSymbol&&tp.ContainingSymbolis not SourceExtensionImplementationMethodSymbol));
46
46
}
47
47
48
48
// Only when the caller passes allowAlpha=true do we tolerate substituted (alpha-renamed) type parameters as keys
Copy file name to clipboardExpand all lines: src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1722,6 +1722,7 @@ public void LanguageVersionAdded_Canary()
1722
1722
// - [ ] replace all references to C# "Next" (such as `TestOptions.RegularNext` or `LanguageVersionFacts.CSharpNext`) with the new version and fix failing tests
1723
1723
// - [ ] update _MaxAvailableLangVersion cap (a relevant test should break when new version is introduced)
1724
1724
// - [ ] update the "UpgradeProject" codefixer
1725
+
// - [ ] test VS insertion
1725
1726
//
1726
1727
// Other repos also need updates:
1727
1728
// - [ ] email release management to add to the release notes. See csharp-version in release.json in previous example: https://github.com/dotnet/core/pull/9493
Copy file name to clipboardExpand all lines: src/Compilers/CSharp/Test/Emit3/Semantics/ExtensionTests.cs
+30-14Lines changed: 30 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -36378,12 +36378,12 @@ static class E
36378
36378
""";
36379
36379
var comp = CreateCompilation(src);
36380
36380
comp.VerifyEmitDiagnostics(
36381
-
// (2,1): error CS1929: 'object' does not contain a definition for 'M' and the best extension method overload 'E.extension<U>(U).M<T>(T)' requires a receiver of type 'U'
36381
+
// (2,1): error CS1973: 'object' has no applicable method named 'M' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.
// (3,1): error CS1929: 'object' does not contain a definition for 'M' and the best extension method overload 'E.extension<U>(U).M<T>(T)' requires a receiver of type 'U'
// (3,1): error CS0176: Member 'E.extension<U>(U).M<T>(T)' cannot be accessed with an instance reference; qualify it with a type name instead
36385
36385
// new object().M(d);
36386
-
Diagnostic(ErrorCode.ERR_BadInstanceArgType, "new object()").WithArguments("object", "M", "E.extension<U>(U).M<T>(T)", "U").WithLocation(3, 1));
36386
+
Diagnostic(ErrorCode.ERR_ObjectProhibited, "new object().M").WithArguments("E.extension<U>(U).M<T>(T)").WithLocation(3, 1));
36387
36387
}
36388
36388
36389
36389
[Fact]
@@ -36432,9 +36432,9 @@ static class E
36432
36432
""";
36433
36433
var comp = CreateCompilation(src);
36434
36434
comp.VerifyEmitDiagnostics(
36435
-
// (2,1): error CS1929: 'object' does not contain a definition for 'M' and the best extension method overload 'E.extension<U>(U).M(object)' requires a receiver of type 'U'
36435
+
// (2,1): error CS1973: 'object' has no applicable method named 'M' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.
// (3,1): error CS1973: 'object' has no applicable method named 'M2' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.
36439
36439
// new object().M2(d);
36440
36440
Diagnostic(ErrorCode.ERR_BadArgTypeDynamicExtension, "new object().M2(d)").WithArguments("object", "M2").WithLocation(3, 1));
@@ -48538,15 +48538,31 @@ public class MyCollection<T> : IEnumerable<T>
// (7,26): error CS9215: Collection expression type 'MyCollection<object>' must have an instance or extension method 'Add' that can be called with a single argument.
// (7,26): error CS1929: 'MyCollection<object>' does not contain a definition for 'Add' and the best extension method overload 'E.extension<T>(MyCollection<T>).Add(T)' requires a receiver of type 'MyCollection<T>'
0 commit comments