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

Support u8 type suffix for UTF8 string literals. #58991

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -296,5 +296,47 @@ public void Errors_12()
}
EOF();
}

[Fact]
public void Interpolation_01()
{
UsingExpression(@"$""hello""u8",
Copy link
Contributor

@RikkiGibson RikkiGibson Jan 21, 2022

Choose a reason for hiding this comment

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

It might be good to modify the proposal to specify what happens when @ or $ prefix is used, and either:

  • the u8 suffix is used, or
  • the new utf8 conversion is used

Intuitively I thought that a constant-valued interpolated string would be fine to use with the u8 suffix, but that doesn't appear to be the case. I don't have a strong position on that, but it seems like whatever is decided should be included in the proposal.
#Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure where confusion is coming from. I think the proposal is clear: "the language will provide the u8 suffix on string literals to force the type to be UTF8." The suffix is for literals, not for constant expressions. Interpolated strings are not literals, even when they have a constant value.

// (1,1): error CS1073: Unexpected token 'u8'
// $"hello"u8
Diagnostic(ErrorCode.ERR_UnexpectedToken, @"$""hello""").WithArguments("u8").WithLocation(1, 1)
);

N(SyntaxKind.InterpolatedStringExpression);
{
N(SyntaxKind.InterpolatedStringStartToken);
N(SyntaxKind.InterpolatedStringText);
{
N(SyntaxKind.InterpolatedStringTextToken);
}
N(SyntaxKind.InterpolatedStringEndToken);
}
EOF();
}

[Fact]
public void Interpolation_02()
{
UsingExpression(@"$@""hello""u8",
// (1,1): error CS1073: Unexpected token 'u8'
// $@"hello"u8
Diagnostic(ErrorCode.ERR_UnexpectedToken, @"$@""hello""").WithArguments("u8").WithLocation(1, 1)
);

N(SyntaxKind.InterpolatedStringExpression);
{
N(SyntaxKind.InterpolatedVerbatimStringStartToken);
N(SyntaxKind.InterpolatedStringText);
{
N(SyntaxKind.InterpolatedStringTextToken);
}
N(SyntaxKind.InterpolatedStringEndToken);
}
EOF();
}
}
}