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

Escape record keywords #74227

Merged
merged 8 commits into from
Jul 18, 2024
Merged

Escape record keywords #74227

merged 8 commits into from
Jul 18, 2024

Conversation

SteveDunn
Copy link
Contributor

See issue #74117 where it was decided that records should be escaped, even though they're not keywords, as it is the safer thing to do.

See other PR #74125

@SteveDunn SteveDunn requested a review from a team as a code owner July 1, 2024 21:17
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 1, 2024
@dotnet-policy-service dotnet-policy-service bot added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Jul 1, 2024
Copy link
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

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

@dotnet/roslyn-compiler for a second review.

return new SymbolDisplayPart(kind, symbol, text);
}

bool isNamedTypeOrAliasName = symbol?.Kind is SymbolKind.NamedType or SymbolKind.Alias;
Copy link
Member

Choose a reason for hiding this comment

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

SymbolKind.Alias

Are we testing the alias case? (See SymbolDisplayTests.TestAlias1 for an example of an alias test.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I have added a test for an alias. If Goo the new Foo? :)


bool isEscapable = IsEscapable(kind);

text = isEscapable ? EscapeIdentifier(text, isNamedTypeOrAliasName) : text;
Copy link
Member

Choose a reason for hiding this comment

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

Consider rearranging to avoid calculating isNamedTypeOrAliasName or reassigning text unnecessarily. Perhaps:

if (_escapeKeywordIdentifiers && IsEscapable(kind))
{
    text = EscapeIdentifer(text, symbol?.Kind is SymbolKind.NamedType or SymbolKind.Alias);
}

Copy link
Contributor Author

@SteveDunn SteveDunn Jul 18, 2024

Choose a reason for hiding this comment

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

Actually, looking at the previous line, we return if !escapeKeywordIdentifers - so we can omit that check here.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we're checking !escapeKeywordIdentifiers earlier but the two if statements could be combined to avoid two return new SymbolDisplayPart(kind, symbol, text);.

@333fred 333fred enabled auto-merge (squash) July 18, 2024 16:42
@333fred 333fred merged commit 46c701c into dotnet:main Jul 18, 2024
24 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jul 18, 2024
@RikkiGibson RikkiGibson modified the milestones: Next, 17.12 P1 Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants