-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Use Pattern Matching suggestion gives faulty code #72370
Comments
Hey, I could take this, but I need some information. I think in this case, you would try to remove the ambiguity by putting a more qualified name such as Program.Cat here, but I don't know if there is logic dedicated to handling this type of syntax generation. If there is, I would like to know more. Also, I would like to know how one would manage the logic of only putting enough qualification to the name to resolve the ambiguity, but not necessarily the fully qualified one as it might not be fully necessary. |
That seems reasonable. Or we could block this case in the analyzer.
You can use the extension GenerateNameSyntax for this purpose.
GenerateNameSyntax will add an annotation to the node asking our simplifier to simplify it. |
I experimented using generator.NameExpression which ends up doing that and it does give me the fully qualified name which works, but now I am hitting a second issue: the simplifier reduces it back to the same ambiguous name. So it seems that there's a part of this where the simplification is uneeded, but now comes the question of how this can be done? It might be possible to manually walk up the names until there's no collisions manually, but now the question becomes how do I know a given name collides? |
The simplifier should be fixed as part of the PR. Thanks :) |
The simplifier can check for this with the name choices it makes. Specifically looking to see if the simple name binds to something like this in a context like this and jsut blacklisting it. |
Version Used: C# 12
Steps to Reproduce:
which gives you a compilation error:
(line 14, col 21): A constant value is expected
Diagnostic Id: IDE0083
Expected Behavior:
No suggestion given.
Actual Behavior:
Faulty suggestion given.
Related discussion:
dotnet/csharplang#7980
The text was updated successfully, but these errors were encountered: