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 expression conversion failure should result in element-wise diagnostics #73297

Closed
RikkiGibson opened this issue May 2, 2024 · 0 comments · Fixed by #73307
Closed
Assignees
Labels
Area-Compilers Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings. New Feature - Collection Expressions untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@RikkiGibson
Copy link
Contributor

RikkiGibson commented May 2, 2024

SharpLab is out of date so you'll have to paste into a console app or similar.

A[] arr = [
    new A(),
    new B() // CS0029: Cannot implicitly convert type 'B' to 'A' (squiggling only 'new B()')
];

M([
    new A(),
    new B()
]); // CS1503: Argument 1: cannot convert from 'collection expressions' to 'A[]' (squiggling the entire collection-expr)

void M(A[] arr) { }

class A { }
class B { }

Expected behavior: both cases report errors on the specific elements which are failing to convert.

Actual behavior: Argument to M gives an error on the entire collection-expr. One can imagine this being unwieldy for large collection-exprs. Only assignment to A[] arr reports element-wise errors in the sample.

It's possible that element-wise conversion errors are not always what we want. But, I am suggesting that we have consistency between conversion diagnostics for assignment and for argument conversions, as a baseline.

I think the reason for the current behavior with arguments has to do with the way overload resolution errors are reported. But it feels like even in overload cases, we should be able to report fine-grained diagnostics, when the candidate we choose for diagnostics doesn't have a conversion from collection-expr, and the parameter type is a collection type.

@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
@RikkiGibson RikkiGibson added Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings. New Feature - Collection Expressions labels May 2, 2024
@cston cston self-assigned this May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings. New Feature - Collection Expressions untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants