dotnet/roslyn

Better handling object initializer syntax error

Open

#22.790 geöffnet am 20. Okt. 2017

Auf GitHub ansehen
 (9 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)C# (4.257 Forks)batch import
Area-CompilersFeature Requesthelp wanted

Repository-Metriken

Stars
 (20.414 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (256 gemergte PRs in 30 T)

Beschreibung

VS 2017 (15.5.0):

There is an error I actually keep doing (my bad) when using the object initializer syntax that is ending the line with a semicolon instead of a comma, e.g.:

return new OperationResponse
{
   SomeProperty= SomeValue,
   AnotherProperty = AnotherValue;
};

please note the semicolon at the end of line AnotherProperty = AnotherValue;. While this is syntax mistake, looks like roslyn is getting confused (a lot actually) with this type of error and put a lot of squiggles under various csharp constructs and starts suggesting wrong things, e.g.

try
{
   return new OperationResponse
   {
      SomeProperty= SomeValue,
      AnotherProperty = AnotherValue;
   };
}
catch (Exception ex) {}

in this case it puts a red squiggle under the curly brace that closes the try statements, and the popup related to the squiggle is something like: the following image

that is a bit misleading.

While this is definitely a cosmetic issue (IMO), I think it would be very cool if roslyn could better handle these type of syntax error, pointing you to the error instead of giving a misleading message.

Contributor Guide