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

Fix suggestions for dotted constant patterns in Color Color case #75373

Merged

Conversation

Rekkonnect
Copy link
Contributor

Fixes #75350

After an offline conversation with @CyrusNajmabadi, this PR only addresses the IDE suggestions, without changing the behavior of binding the symbol, or the parsed syntax. We simply reinterpret the non-const symbol as a type and suggest off of the type symbol.

@Rekkonnect Rekkonnect requested a review from a team as a code owner October 3, 2024 23:50
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Oct 3, 2024
@dotnet-policy-service dotnet-policy-service bot added Community The pull request was submitted by a contributor who is not a Microsoft employee. VSCode labels Oct 3, 2024
var reinterpretedBinding = semanticModel.GetSpeculativeSymbolInfo(identifier.SpanStart, identifier, SpeculativeBindingOption.BindAsTypeOrNamespace);
var reinterpretedSymbol = reinterpretedBinding.GetAnySymbol();

// The reinterpretation must be a type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because...?

(this comment explains what the code does, but not why).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an oversight. We also want to allow other kinds of symbols like aliases, namespaces and types. Will update, including a reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, ptal

// Methods, properties, events, non-constant fields etc. are excluded since they are not constant expressions
bool FilterMember(ISymbol symbol)
{
return symbol is INamespaceOrTypeSymbol or IFieldSymbol { IsConst: true }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about a constant local? can you add a test for that?

Copy link
Contributor Author

@Rekkonnect Rekkonnect Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Local symbols are not contained within a type or namespace, so we will never encounter those through the filtering. However, we should have tests to make sure they are not overlooked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests showing the behavior in locals

@CyrusNajmabadi
Copy link
Member

Done with pass. looking good.

@CyrusNajmabadi CyrusNajmabadi merged commit 8a6edcd into dotnet:main Oct 7, 2024
25 checks passed
@CyrusNajmabadi
Copy link
Member

Thanks!

@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Oct 7, 2024
@Rekkonnect Rekkonnect deleted the fix/75350-switch-expression-color-color branch October 7, 2024 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. untriaged Issues and PRs which have not yet been triaged by a lead VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No suggestions in switch expression arm when dotting on an enum type in a Color Color case
2 participants