Skip to content

Adjust DefiniteAssignmentPass.WriteConsideredUse for UTF8 String Literals.#60326

Merged
AlekseyTs merged 2 commits intodotnet:features/Utf8StringLiteralsfrom
AlekseyTs:Utf8StringLiterals_18
Mar 24, 2022
Merged

Adjust DefiniteAssignmentPass.WriteConsideredUse for UTF8 String Literals.#60326
AlekseyTs merged 2 commits intodotnet:features/Utf8StringLiteralsfrom
AlekseyTs:Utf8StringLiterals_18

Conversation

@AlekseyTs
Copy link
Copy Markdown
Contributor

Fixes #60319.

@AlekseyTs
Copy link
Copy Markdown
Contributor Author

@cston, @RikkiGibson, @dotnet/roslyn-compiler Please review


if ((object)type != null && type.IsReferenceType &&
type.SpecialType != SpecialType.System_String &&
(type is not ArrayTypeSymbol { IsSZArray: true } arrayType || arrayType.ElementType.SpecialType != SpecialType.System_Byte))
Copy link
Copy Markdown
Member

@RikkiGibson RikkiGibson Mar 23, 2022

Choose a reason for hiding this comment

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

Consider combining into a single pattern like type is not ArrayTypeSymbol { IsSZArray: true, ElementType.SpecialType: SpecialType.System_Byte } #Resolved

const string stringNull = null;

var x1 = ""123""U8;
Span<byte> x2 = ""124""U8;
Copy link
Copy Markdown
Member

@RikkiGibson RikkiGibson Mar 23, 2022

Choose a reason for hiding this comment

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

Is it intentional that the warning is not given here even though it is given on 'z2'? #Resolved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is it intentional that the warning is not given here even though it is given on 'z2'?

This is similar to System.ReadOnlySpan<char> x3 = "abc";. A user defined conversion considered as a usage.
On z2 there is no user-defined conversion from the language point of view, there is a built-in conversion.

@AlekseyTs
Copy link
Copy Markdown
Contributor Author

@cston, @dotnet/roslyn-compiler For the second review.

@AlekseyTs
Copy link
Copy Markdown
Contributor Author

@cston, @dotnet/roslyn-compiler For the second review.

@AlekseyTs AlekseyTs merged commit fe2c5dd into dotnet:features/Utf8StringLiterals Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants