-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Prefer expanded form for error reporting when params arguments are convertible #81276
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
+91
−2
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7f2b7da
Initial plan
Copilot e36888d
Fix overload resolution error reporting for params collections
Copilot bf126f6
Prefer expanded form when normal form has bad params argument
Copilot 7266c99
Lint
CyrusNajmabadi 50eb025
Simplify PreferExpandedFormOverNormalForm logic
Copilot e0619f9
Update WorkItem URLs to reference correct issue #12933
Copilot 4438555
Remove source code comments from test methods
Copilot 7371ccd
Add test for issue #43920
Copilot eeb9e7b
Add test case for issue #43920 with string params signature
Copilot 4e72746
Remove comments from within test string literals
Copilot d9fdecd
Merge remote-tracking branch 'upstream/main' into copilot/fix-string-…
CyrusNajmabadi 1bc451d
Fix baselines
CyrusNajmabadi 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 |
|---|---|---|
|
|
@@ -11945,5 +11945,88 @@ readonly struct S | |
| """; | ||
| CreateCompilation(source).VerifyDiagnostics(); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/12933")] | ||
| public void ParamsErrorSuppression_StringConvertibleToObject() | ||
| { | ||
| var source = """ | ||
| class Program | ||
| { | ||
| static void M(char c, params object[] args) { } | ||
|
|
||
| static void Test(string[] arr) | ||
| { | ||
| M(arr, "test"); | ||
| } | ||
| } | ||
| """; | ||
| CreateCompilation(source).VerifyDiagnostics( | ||
| // (7,11): error CS1503: Argument 1: cannot convert from 'string[]' to 'char' | ||
| // M(arr, "test"); | ||
| Diagnostic(ErrorCode.ERR_BadArgType, "arr").WithArguments("1", "string[]", "char").WithLocation(7, 11)); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/12933")] | ||
| public void ParamsErrorSuppression_IntNotConvertibleToString() | ||
| { | ||
| var source = """ | ||
| class C | ||
| { | ||
| static void M(char c, params string[] args) { } | ||
|
|
||
| static void Test() | ||
| { | ||
| M(1, 2); | ||
| } | ||
| } | ||
| """; | ||
| CreateCompilation(source).VerifyDiagnostics( | ||
| // (7,11): error CS1503: Argument 1: cannot convert from 'int' to 'char' | ||
| // M(1, 2); | ||
| Diagnostic(ErrorCode.ERR_BadArgType, "1").WithArguments("1", "int", "char").WithLocation(7, 11), | ||
| // (7,14): error CS1503: Argument 2: cannot convert from 'int' to 'string' | ||
| // M(1, 2); | ||
| Diagnostic(ErrorCode.ERR_BadArgType, "2").WithArguments("2", "int", "string").WithLocation(7, 14)); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/43920")] | ||
| public void ParamsErrorSuppression_Issue43920() | ||
| { | ||
| var source = """ | ||
| class Program | ||
| { | ||
| static void M(int x, params object[] args) { } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| static void Test() | ||
| { | ||
| M("wrong", "test"); | ||
| } | ||
| } | ||
| """; | ||
| CreateCompilation(source).VerifyDiagnostics( | ||
| // (7,11): error CS1503: Argument 1: cannot convert from 'string' to 'int' | ||
| // M("wrong", "test"); | ||
| Diagnostic(ErrorCode.ERR_BadArgType, @"""wrong""").WithArguments("1", "string", "int").WithLocation(7, 11)); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/43920")] | ||
| public void ParamsErrorSuppression_Issue43920_StringParams() | ||
| { | ||
| var source = """ | ||
| class Program | ||
| { | ||
| static void A(string a, params string[] b) { } | ||
|
|
||
| static void Test() | ||
| { | ||
| A(1, "test"); | ||
| } | ||
| } | ||
| """; | ||
| CreateCompilation(source).VerifyDiagnostics( | ||
| // (7,11): error CS1503: Argument 1: cannot convert from 'int' to 'string' | ||
| // A(1, "test"); | ||
| Diagnostic(ErrorCode.ERR_BadArgType, "1").WithArguments("1", "int", "string").WithLocation(7, 11)); | ||
| } | ||
| } | ||
| } | ||
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.