Skip to content
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

Collection expressions: report specific conversion errors from overload resolution #73307

Merged
merged 1 commit into from
May 30, 2024

Conversation

cston
Copy link
Member

@cston cston commented May 2, 2024

Fixes #73297

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels May 2, 2024
@cston cston marked this pull request as ready for review May 3, 2024 21:02
@cston cston requested a review from a team as a code owner May 3, 2024 21:02
@cston
Copy link
Member Author

cston commented May 16, 2024

@dotnet/roslyn-compiler, please review.

@RikkiGibson RikkiGibson self-assigned this May 16, 2024
@@ -1231,6 +1231,10 @@ private static bool HadLambdaConversionError(BindingDiagnosticBag diagnostics, A
{
// a diagnostic has been reported by ReportDelegateOrFunctionPointerMethodGroupDiagnostics
}
else if (argument.Kind == BoundKind.UnconvertedCollectionExpression)
{
binder.GenerateImplicitConversionErrorForCollectionExpression((BoundUnconvertedCollectionExpression)argument, parameterType, diagnostics);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! That was easy. :)

{
string source = """
ERROR[] values = [1];
values = [2];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's interesting, and seems reasonable I guess, as an "avoid cascading" behavior? Is this similar to how values = new[] { 2 } would behave?

Copy link
Member Author

@cston cston May 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the behavior is similar for values = new[] { 2 } which doesn't result in an error (since it is assumed an error was reported on the declaration of ERROR[] values;.

However, the error that is suppressed in values = new[] { 2 } is converting int[] to ERROR[], whereas with values = [2] the error that is suppressed is converting int to ERROR.

Also, the error reporting for assignment did not change in this PR - I added this test to show the similar diagnostics to the previous test InAttribute_BadArrayType() which was affected by this PR. In that test, a call to [X(new[] { 2 })] will result in a conversion error for the argument.

I'm on the fence about whether we should report an error at the for [X([1])] in that test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, the error that is suppressed in values = new[] { 2 } is converting int[] to ERROR[], whereas with values = [2] the error that is suppressed is converting int to ERROR.

Another example is values = default which does not result in any additional error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that all sounds good, merge at will :)

@RikkiGibson RikkiGibson requested a review from a team May 20, 2024 22:42
@cston
Copy link
Member Author

cston commented May 30, 2024

/azp run roslyn-CI

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@cston cston merged commit b7b602f into dotnet:main May 30, 2024
24 checks passed
@cston cston deleted the 73297 branch May 30, 2024 21:38
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Collection expression conversion failure should result in element-wise diagnostics
3 participants