razor icon indicating copy to clipboard operation
razor copied to clipboard

compiler errors without squiggling when attribute contains @() blocks without space

Open AdmiralSnyder opened this issue 1 year ago • 4 comments

In a razor file, i have an element with an attribute, and in that, there are two @() blocks containing something - if those blocks aren't separated by a string, compilation fails, but there's no squiggle in the editor. See screenshot image

AdmiralSnyder avatar Feb 24 '24 01:02 AdmiralSnyder

there's no squiggle in the editor

This would be tooling, but looks to me like the compiler shouldn't be erroring on this, or perhaps should be offering a better RZ diagnostic if this scenario isn't supported, so moving to compiler to have a first look.

davidwengier avatar Feb 24 '24 01:02 davidwengier

I think the compiler's behavior here is by design - all consecutive C# expressions are concatenated and treated as one expression. For example,

<input value="@(1+)@(2)" />

will render as

<input value="3" />

Changing that would be a breaking change. So in the original example, @("HELLO")@("WORLD") is translated to C# "HELLO""WORLD" which gives those errors. And the compiler cannot report a better RZ diagnostic here as it doesn't know whether there's an error in the first place.

jjonescz avatar Feb 26 '24 14:02 jjonescz

That is bizarre and scary, I had no idea. Would love to see that change in a warning wave, as I can see why someone might want @(myThing.Name)@(myThing.Suffix) for example, but I'm failng to see the benefit of @(1+)@(2). Especially considering interpolated strings in Razor are only accidental.

<input value="@(1+)@(2)" /> is angry_jaredpar worthy 😁

davidwengier avatar Feb 26 '24 20:02 davidwengier

@phil-allen-msft Compiler is working as expected, so moving to tooling for triage of the squiggles not showing.

chsienki avatar Mar 12 '24 21:03 chsienki