dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.06k stars 4.04k forks source link

Identifier expected #45028

Open iam3yal opened 4 years ago

iam3yal commented 4 years ago

Version Used: 16.6.1

I'm not sure when it happens so can't provide reproductions steps but it happens in this section of the code.

Identifier expected

Steps to Reproduce:

  1. Paste the following code:

    class Program
    {
    static void Main(string[] args)
    {
        int start = 0, end = 0;
    
        if (true)
        {
        }
    
        Foo(start..end);
    }
    
    static void Foo(Range range) { }
    }
  2. Remove the opening braces from the if statement like so:

    if (true)
    }
  3. Wait for red squiggles to appear.

  4. Undo recent changes or add back the opening braces.

  5. The red squiggles should still appear under the binary infix operator .. saying "Identifier expected".

Expected Behavior:

No red squiggles when the opening braces are added.

Actual Behavior:

Red squiggles but the code compiles just fine.

CyrusNajmabadi commented 4 years ago

Tagging @agocke. Potentially an incremental parsing issue? @eyalsk I'm guessing if you save and close the file, and then reopen it/VS, that the error goes away?

iam3yal commented 4 years ago

@CyrusNajmabadi yup, seems like it, it comes and goes.

jinujoseph commented 4 years ago

@eyalsk it looks like an extension is in use that doesn't support C# 8.0's range syntax .

iam3yal commented 4 years ago

@jinujoseph Okay, thank you, it would have been nice if VS could note what extension caused it.

iam3yal commented 4 years ago

I've disabled all of my addons which I only have a few, now, when you disable the addons the red squiggles don't disappear immediately so I need to start guessing, I find this experience unpleasant.

jnm2 commented 4 years ago

I repro'd the exact same thing yesterday but can't get it to repro today. I haven't updated anything.

CyrusNajmabadi commented 4 years ago

Sounds like an incremental parsing bug somewhere

jnm2 commented 4 years ago

Possibly sharing a root cause with the SyntaxNode enumeration race condition? https://github.com/dotnet/roslyn/issues/41526

CyrusNajmabadi commented 4 years ago

Tagging @agocke . I'm guessing incremental parsing bug here. Thank fully @eyalsk found a repro!