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

IDE0306 triggers for invalid case and the fix generate wrong code #7596

Open
wiz0u opened this issue Mar 8, 2025 · 0 comments
Open

IDE0306 triggers for invalid case and the fix generate wrong code #7596

wiz0u opened this issue Mar 8, 2025 · 0 comments

Comments

@wiz0u
Copy link

wiz0u commented Mar 8, 2025

Analyzer

IDE0306 Collection initialization can be simplified
triggers for code such as:

var array = new[] { 1, 2, 3 };
Dictionary<int, int> dict;
Queue<int> queue;
// IDE0306 on those lines:
dict = new(array.Select(i => KeyValuePair.Create(i, i)));
queue = new(array);

For both cases, applying the suggested fix creates incorrect code with the [.. notation]

Expected: IDE0306 doesn't trigger on such lines (when there is no Add method?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant