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

Possible verbatim string literal regression #10568

Closed
SteveSandersonMS opened this issue Jul 2, 2024 · 9 comments · Fixed by #11086
Closed

Possible verbatim string literal regression #10568

SteveSandersonMS opened this issue Jul 2, 2024 · 9 comments · Fixed by #11086
Assignees
Labels
area-compiler Umbrella for all compiler issues area-parsing

Comments

@SteveSandersonMS
Copy link
Member

Repro code in any .razor file:

@for(var i = 0; i < 3; i++)
{
    var filename = @$"ticket-{i}.png";
    <h1>@filename</h1>
}

This is legal code as far as I know and used to work without errors or warnings. However in Version 17.11.0 Preview 2.0 this shows an error:

Severity	Code	Description	Project	File	Line	Suppression State	Details
Error (active)	RZ1009	The "@" character must be followed by a ":", "(", or a C# identifier.  If you intended to switch to markup, use an HTML start tag, for example: ...

On my machine this appears in the VS Error UI but does not occur during command-line compilation (probably a slightly older SDK).

@davidwengier davidwengier added the area-compiler Umbrella for all compiler issues label Jul 2, 2024
@jjonescz
Copy link
Member

jjonescz commented Jul 3, 2024

Looks like this is caused by #10232. cc @333fred

@333fred
Copy link
Member

333fred commented Jul 3, 2024

This will be solved by the lexer changes.

This is legal code as far as I know

Not really. Interpolated strings of any kind have never been actually supported by the razor parser. I agree that they should be, and the lexer changes will actually support them, but any amount of interpolated strings working has simply been a happy accident, not intentional implementation.

@333fred
Copy link
Member

333fred commented Jul 11, 2024

Oh, I almost forgot to mention: a workaround is just switching from @$ to $@ here.

@AMUCOMO
Copy link

AMUCOMO commented Aug 28, 2024

I also noticed this bug, but only after updating my VS Version to 17.11.2 (current latest), seemed to work before in 17.10.*
in any .razor file:
@{ string foo = @$"""a"; }

@ssg
Copy link

ssg commented Aug 30, 2024

any amount of interpolated strings working has simply been a happy accident, not intentional implementation.

Accident or not, it was still a behavior relied by applications. This impacts existing applications in the wild as it blocks their migration path to newer .NET versions and might cause unnoticed regressions of varying severity especially when apps use runtime compilation. The workaround isn't obvious either.

Solely updating to a newer .NET version ideally should never break a running app. But, in case it does, the breaking changes should also be documented clearly.

Was this breaking change known when this patch was approved?

What's the course of action to reduce the impact?

"We do not break the userspace" --Linus Torvalds.

@333fred
Copy link
Member

333fred commented Aug 30, 2024

Was this breaking change known when this patch was approved?

This particular flavor of the change was not not known, but we did know the change would cause breaks in general.

What's the course of action to reduce the impact?

As mentioned earlier, switch @$ to $@.

@AMUCOMO
Copy link

AMUCOMO commented Sep 10, 2024

I have found another piece of code that stopped compiling after the 17.11.2 VS update. Maybe this is also be connected to the change in parsing razor code? Documented here https://developercommunity.visualstudio.com/t/Regression-in-VS-17112-in-Razor-parser/10741925

@333fred
Copy link
Member

333fred commented Sep 10, 2024

@AMUCOMO that's probably #10737. Related, but not quite the same.

333fred added a commit that referenced this issue Oct 25, 2024
This adds the new roslyn-based tokenizer, off by default, which uses
Roslyn, instead of a native tokenizer, to tokenize C# code. This is a
major change and will be enabled by putting
`<Features>use-roslyn-tokenizer</Features>` in the project file.

Closes #10737
Closes #10568
Closes #7084
@davidwengier
Copy link
Contributor

Proof!

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-compiler Umbrella for all compiler issues area-parsing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants