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

Adding semicolon inbetween property name and { get; set; } invalidates rest of the document (excess errors) #52

Closed
NTaylorMullen opened this issue Jan 21, 2015 · 5 comments · Fixed by #65089
Labels
Area-Compilers Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings. Feature Request
Milestone

Comments

@NTaylorMullen
Copy link
Contributor

Repro:

public class Class
{
    public int MyProperty; { get; set; }

    // Pretty much anything here causes an error
}

Note the ; after MyProperty and before { get; set; }

Expected:
Rest of document not being invalidated and an error that points to the property.

Notes:

When generating code for Razor there have been some cases of users adding semicolons after @inject statements resulting in the entire document being invalidated (tons of errors) after

@paulomorgado
Copy link

Although the intention might have been to declare a property, public int MyProperty; is a valid field declaration.

That makes the { invalid no matter what comes next.

@NTaylorMullen
Copy link
Contributor Author

@paulomorgado of course, but invalidating the entire remaining document seems way overkill. You still need to balance the {, the error should only encompass the balancing of the curly braces.

@theoy
Copy link
Contributor

theoy commented Jan 23, 2015

Interesting error recovery case :)

@theoy theoy added this to the Unknown milestone Jan 23, 2015
@paulomorgado
Copy link

I'm curious. How would you recover from that error, @NTaylorMullen?

@NTaylorMullen
Copy link
Contributor Author

@paulomorgado { get; set; } is invalid C# by itself. Whatever is encapsulated inside of the {...} should be handled as an individual error and not affect code past it.

If a user were to type: { get; set; without the ending } then it'd be a different situation because there'd be unbalanced curly braces; therefore, it may make sense to invalidate the rest of the document in that case.

To sum it all up, if you encounter any variation of { get; set; } without a corresponding property name/type the recovery is to find the next piece of valid standalone C# and mark the previous { ... } as errored code.

I'm not entirely familiar with the parsing logic/behavior done in Roslyn so I apologize for not being able to go more into familiar detail but that is how we would do it in Razor.

@VSadov VSadov added Enhancement and removed Bug labels Mar 16, 2015
@jaredpar jaredpar removed this from the Unknown milestone Nov 23, 2015
@gafter gafter added the Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings. label Dec 2, 2015
@dpoeschl dpoeschl added this to the Unknown milestone Dec 3, 2015
dibarbet added a commit to dibarbet/roslyn that referenced this issue Mar 1, 2023
Use new roslyn to fix options exceptions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings. Feature Request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants