-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
convert to constant pattern
assist in the wrong place
#56763
Comments
Summary: The "convert to constant pattern" assist is incorrectly suggesting to add |
That looks correct. The reason the result looks wrong is likely that the code is wrong, but now you can see it. |
Hmm ,what's the meaning of String() in this context then ? |
The object pattern |
Also String _ is triggered by using |
The It changes the meaning of the pattern, but likely to what you would have wanted. The biggest issue here is how one can figuring out which assist to use. The analyzer gives a warning of
but it doesn't link that to the "convert to wildcard pattern". Use the wildcard pattern `String _` instead of a type literal. it would be easier to know to choose "convert to wildcard pattern". |
I guess so , should i close this now then? |
This would be better, yes. And also as mentioned:
I believe this would help a lot of users. |
@lrhn I was chatting with @AbdeMohlbi before this issue was made. I think there's a misunderstanding about why this issue was made. Specifically with regards to:
What @AbdeMohlbi wanted here was not to preserve the original behavior. Because the original behavior was incorrect. They misused patterns and forgot to specify They didn't truly want to do In short, what was expected here was an assist that converts: switch (any) {
case Type:
} into: switch (any) {
case Type():
} I think when we use |
That's what i meant but i guess idon't have enough dart-related-knowledge to say that |
When I check the example program in DartPad, I get two suggestions: "convert to wildcard pattern" and "convert to constant pattern", in that order. (And then some "ignore " here or in the entire file options.) The first one does what you want. It converts a The second one converts the I think having both fixes is a good compromise. By writing just It's not a problem to have the second fix. My only worry is that it's not easy to understand which fix does what, and why. |
Yes, also in the original example on Discord, the switch was on |
That's why I agree about adding more explicit cases to the docs for both Explaining why this should be done over type checking in most cases. About the fixes, I'm not sure how we can solve this right now. Maybe adding a link to the docs in cases like this similar to what lints do at the end on their names. There is an issue to add a link to the docs on keywords that would help as well: #50085. |
Here is one linter issue related to this discussion but I don't see any mentions of calling out that the user is switching on |
consider this code :
this code will trigger
convert to constant pattern
assist , i guess this is a wrong suggestion in this case beacause the code would became :@FMorschel could u confirm this ?
The text was updated successfully, but these errors were encountered: