-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Extensions: fix issue with GetParameterOrExtensionParameter #79402
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14361,5 +14361,211 @@ public static class E | |
| var extension = (SourceNamedTypeSymbol)comp.GetMember<NamedTypeSymbol>("E").GetTypeMembers().Single(); | ||
| AssertEx.Equal("extension([MyAttribute/*()*/] System.Int32)", extension.ComputeExtensionMarkerRawName()); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/79193")] | ||
| public void OverloadResolution_01() | ||
| { | ||
| var src = """ | ||
| public static class E | ||
| { | ||
| extension(object @this) | ||
| { | ||
| public void M<T>(T x) | ||
| { | ||
| @this.M(x, default); | ||
| } | ||
|
|
||
| public void M(params System.ReadOnlySpan<object> span) | ||
| { | ||
| } | ||
|
|
||
| private void M<T>(T x, System.ReadOnlySpan<object> span) | ||
| { | ||
| } | ||
| } | ||
| } | ||
| """; | ||
| var comp = CreateCompilation(src, targetFramework: TargetFramework.Net90); | ||
| comp.VerifyEmitDiagnostics(); | ||
|
||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/79193")] | ||
| public void OverloadResolution_02() | ||
| { | ||
| var src = """ | ||
| new object().M(a: null); | ||
|
|
||
| public static class E | ||
| { | ||
| extension(object o1) | ||
| { | ||
| public void M(object a) { } | ||
|
|
||
| public void M(string a) { System.Console.Write("ran"); } | ||
| } | ||
| } | ||
| """; | ||
| var comp = CreateCompilation(src); | ||
| CompileAndVerify(comp, expectedOutput: "ran").VerifyDiagnostics(); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/79193")] | ||
| public void OverloadResolution_03() | ||
| { | ||
| var src = """ | ||
| new object().M(a: null); | ||
|
|
||
| public static class E | ||
| { | ||
| extension(object o1) | ||
| { | ||
| public void M(object a) { } | ||
| } | ||
|
|
||
| public static void M(this object o, string a) { System.Console.Write("ran"); } | ||
| } | ||
| """; | ||
| var comp = CreateCompilation(src); | ||
| CompileAndVerify(comp, expectedOutput: "ran").VerifyDiagnostics(); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/79193")] | ||
| public void OverloadResolution_04() | ||
| { | ||
| var src = """ | ||
| new object().M(a: null); | ||
|
|
||
| public static class E | ||
| { | ||
| extension(object o1) | ||
| { | ||
| public void M(string a) { System.Console.Write("ran"); } | ||
| } | ||
|
|
||
| public static void M(this object o, object a) { } | ||
| } | ||
| """; | ||
| var comp = CreateCompilation(src); | ||
| CompileAndVerify(comp, expectedOutput: "ran").VerifyDiagnostics(); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/79193")] | ||
| public void OverloadResolution_05() | ||
| { | ||
| var src = """ | ||
| new object().M(a: null); | ||
|
|
||
| public static class E | ||
| { | ||
| extension(object o1) | ||
| { | ||
| public void M(object a) { } | ||
| public void M(params int[] a) { System.Console.Write("ran"); } | ||
| } | ||
| } | ||
| """; | ||
| var comp = CreateCompilation(src); | ||
| CompileAndVerify(comp, expectedOutput: "ran").VerifyDiagnostics(); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/79193")] | ||
| public void OverloadResolution_06() | ||
| { | ||
| var src = """ | ||
| new object().M(1, 2); | ||
|
|
||
| public static class E | ||
| { | ||
| extension(object o1) | ||
| { | ||
| public void M(int x1, int x2) { System.Console.Write("ran"); } | ||
| public void M(params int[] a) { } | ||
| } | ||
| } | ||
| """; | ||
| var comp = CreateCompilation(src); | ||
| CompileAndVerify(comp, expectedOutput: "ran").VerifyDiagnostics(); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/79193")] | ||
| public void OverloadResolution_07() | ||
| { | ||
| var src = """ | ||
| new object().M(a: 1, 2); | ||
|
|
||
| public static class E | ||
| { | ||
| extension(object o1) | ||
| { | ||
| public void M(int a, int b) { System.Console.Write("ran"); } | ||
| public void M(params int[] a) { } | ||
| } | ||
| } | ||
| """; | ||
| var comp = CreateCompilation(src); | ||
| CompileAndVerify(comp, expectedOutput: "ran").VerifyDiagnostics(); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/79193")] | ||
| public void OverloadResolution_08() | ||
| { | ||
| var src = """ | ||
| new object().M(index: 0, 1, 2); | ||
|
|
||
| public static class E | ||
| { | ||
| extension(object o1) | ||
| { | ||
| public void M(int index, int a, int b) { System.Console.Write("ran"); } | ||
| public void M(int index, params int[] a) { } | ||
| } | ||
| } | ||
| """; | ||
| var comp = CreateCompilation(src); | ||
| CompileAndVerify(comp, expectedOutput: "ran").VerifyDiagnostics(); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/79193")] | ||
| public void OverloadResolution_09() | ||
| { | ||
| var src = """ | ||
| object.M(index: 0, 1, 2); | ||
|
|
||
| public static class E | ||
| { | ||
| extension(object) | ||
| { | ||
| public static void M(int index, int a, int b) { System.Console.Write("ran"); } | ||
| public static void M(int index, params int[] a) { } | ||
| } | ||
| } | ||
| """; | ||
| var comp = CreateCompilation(src); | ||
| CompileAndVerify(comp, expectedOutput: "ran").VerifyDiagnostics(); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/79193")] | ||
| public void OverloadResolution_10() | ||
| { | ||
| var src = """ | ||
| 1.M(2); | ||
|
|
||
| public static class E | ||
| { | ||
| extension(params int[] i) | ||
| { | ||
| public static void M() { } | ||
| } | ||
| } | ||
| """; | ||
| var comp = CreateCompilation(src); | ||
| comp.VerifyEmitDiagnostics( | ||
| // (5,15): error CS1670: params is not valid in this context | ||
| // extension(params int[] i) | ||
| Diagnostic(ErrorCode.ERR_IllegalParams, "params").WithLocation(5, 15), | ||
| // (1,3): error CS1501: No overload for method 'M' takes 1 arguments | ||
| // 1.M(2); | ||
| Diagnostic(ErrorCode.ERR_BadArgCount, "M").WithArguments("M", "1").WithLocation(1, 3)); | ||
| } | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Let's make this a local function in BetterFunctionMember. It looks like it is used only in that function, and that function is a source of mismatch between parameters and arguments,