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

Error recovery when an expression is not provided is very poor #10383

Open
DoctorKrolic opened this issue May 18, 2024 · 1 comment
Open

Error recovery when an expression is not provided is very poor #10383

DoctorKrolic opened this issue May 18, 2024 · 1 comment
Labels
area-compiler Umbrella for all compiler issues untriaged

Comments

@DoctorKrolic
Copy link
Contributor

VS version:
17.10 Preview 7

Steps to reproduce:

  1. Create a sample blazor web app
  2. Go to Counter.razor
  3. Remove IncrementCount from @onclick handler, resulting in @onclick=""

Expected behavior:
I see an single-charachter error on "" similar as how C# would do in such cases:
devenv_HqRioP77YN

Actual behavior:

  1. Error location takes seemingly random half of the file:
    devenv_xeH5q3TkEw
  2. There are actually 2 errors: CS1525: Invalid expression term ')' and a razor-specific error RZ2008: Attribute '@onclick' on tag helper element 'button' requires a value. Tag helper bound attributes of type 'Microsoft.AspNetCore.Components.EventCallback<Microsoft.AspNetCore.Components.Web.MouseEventArgs>' cannot be empty or contain only whitespace. The first one shouldn't be there at all since it is an implementation detail of how razor works. The second one, although, very accurate, seems to be an overkill to me. Having just something like a C# error CS1733: Expression expected would be way easier to read and parse in my head, while would still be pretty accurate - after all, an expression returning a delegate of several allowed shapes is expected to be there.

Additional info:
This happens quite a lot in the middle of an edit to a file. And it is pretty annoying to see half of the file become one giant error several times in a row as you type.

@davidwengier davidwengier added the area-compiler Umbrella for all compiler issues label May 18, 2024
@davidwengier
Copy link
Contributor

Personally speaking I've been of the opinion that if the compiler can produce an RZ diagnostic, it shouldn't produce C# code that will also have its own diagnostics. That does affect tooling scenarios though (eg, if there is no C# generated than how do we provide completion when the user invokes it in the attribute value?) so it might not always be possible.

I've labelled this as compiler, but it might be that tooling can make some changes here too, like not reporting the CS diagnostics if they overlap an RZ? Maybe needs a bit of a design process encompassing both teams.

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 untriaged
Projects
None yet
Development

No branches or pull requests

2 participants