dotnet / dotnet/roslyn

Error recovery when an expression is not provided is very poor

Open
#85,529 3 comments 6 reactions 1 assignee Claimed by @chsienki View on GitHub
Area-Razor Area-Razor-Compiler
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

**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](https://github.com/dotnet/roslyn/assets/70431552/2d366fea-9fb4-481f-8dd2-2c5000e78b23)

**Actual behavior:**
1. Error location takes seemingly random half of the file:
![devenv_xeH5q3TkEw](https://github.com/dotnet/roslyn/assets/70431552/abd0245c-e37b-4bcd-b168-0dbe5adc7d83)
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' 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](https://learn.microsoft.com/en-us/dotnet/csharp/misc/cs1733) 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.