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

Unnecessary new for tuple constuction #7537

Open
kevinoid opened this issue Jan 19, 2025 · 0 comments
Open

Unnecessary new for tuple constuction #7537

kevinoid opened this issue Jan 19, 2025 · 0 comments

Comments

@kevinoid
Copy link

Describe the problem you are trying to solve

Inconsistent use of new for tuple construction making code misleading or harder to read.

In several situations, tuple can be constructed either from a tuple_expression or by a target_typed_new expression. For example:

(int Min, int Max) b1 = (1, 2);
(int Min, int Max) b2 = new(1, 2);

It would be nice to have an analyzer rule to prefer one form or the other for consistency. Personally, I find the new both unnecessary and misleading when the type is less obvious.

Describe suggestions on how to achieve the rule

Warn when a non-empty target_typed_new expression is used to construct ValueTuple<>.

Additional context

Perhaps these expressions differ in ways I'm unaware of and there is reason to mix both in a project?

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