Skip to content

Don't offer to simply to an alias if it has a different meaning#57001

Merged
davidwengier merged 7 commits intodotnet:mainfrom
davidwengier:FixSimplifyAlias
Nov 20, 2021
Merged

Don't offer to simply to an alias if it has a different meaning#57001
davidwengier merged 7 commits intodotnet:mainfrom
davidwengier:FixSimplifyAlias

Conversation

@davidwengier
Copy link
Copy Markdown
Member

Fixes #56882

@davidwengier davidwengier requested a review from a team as a code owner October 7, 2021 07:58
@ghost ghost added the Area-IDE label Oct 7, 2021
Copy link
Copy Markdown
Contributor

@ryzngard ryzngard left a comment

Choose a reason for hiding this comment

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

Looks reasonable. One question about implementation, but I honestly don't know of a scenario where it would break.

@sharwell sharwell dismissed their stale review October 7, 2021 15:34

I misread the existing test.

var symbols = semanticModel.LookupSymbols(node.SpanStart, name: aliasName);
if (symbols.Any(s => !s.Equals(aliasReplacement)))
var aliasIdentifier = SyntaxFactory.IdentifierName(aliasName);
var typeInfo = semanticModel.GetSpeculativeTypeInfo(node.SpanStart, aliasIdentifier, SpeculativeBindingOption.BindAsExpression);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

aliases can alias more than just types. they can also alias namespaces. i would get GetSpeculativeSymbolInfo and validate that the symbols are the same. note: plz add test for this as well :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Updated to check symbol info first, you were right namespaces were broken. Added a bunch of tests.

validate that the symbols are the same

so I'm still using TypeInfo too because the symbols don't have to be the same in all cases. Hopefully thats okay. I could avoid it and do the "long hand" way of checking for IPropertySymbol and then its type, or IParameterSymbol and its type etc. so let me know if thats preferrable.

@davidwengier davidwengier merged commit 33b168e into dotnet:main Nov 20, 2021
@davidwengier davidwengier deleted the FixSimplifyAlias branch November 20, 2021 22:16
@ghost ghost added this to the Next milestone Nov 20, 2021
@allisonchou allisonchou modified the milestones: Next, 17.1.P2 Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simplify member access (IDE0002) code style rule suggestion generates broken code

5 participants