razor
razor copied to clipboard
compiler errors without squiggling when attribute contains @() blocks without space
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
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.
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.
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 😁
@phil-allen-msft Compiler is working as expected, so moving to tooling for triage of the squiggles not showing.