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

Incorrect location for missing semicolon error after whitespace change #31161

Open
svick opened this issue Nov 14, 2018 · 2 comments
Open

Incorrect location for missing semicolon error after whitespace change #31161

svick opened this issue Nov 14, 2018 · 2 comments
Labels
Area-Compilers Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it Language-C#
Milestone

Comments

@svick
Copy link
Contributor

svick commented Nov 14, 2018

Version Used: 2.9.0, 2.11.0-beta3-63513-06

Steps to Reproduce:

Run the following code:

using System;
using System.Globalization;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;

class Program
{

    static void Main()
    {
        CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;

        string code = @"class C
{
    void M()
    {
        M()
    }
}";

        var node1 = SyntaxFactory.ParseCompilationUnit(code);

        Dump(node1);

        var node2 = node1.NormalizeWhitespace();

        Dump(node2);

        void Dump(SyntaxNode node)
        {
            Console.WriteLine(node);

            foreach (var diagnostic in node.GetDiagnostics())
            {
                Console.WriteLine(diagnostic);
            }
        }
    }
}

Expected Behavior:

Both syntax trees report the missing semicolon error just after the closing parenthesis on line 5. In other words, in both cases, the reported location should be (5,12).

Actual Behavior:

In the second syntax tree, the reported location is (5, 10), i.e. on the opening parenthesis:

class C
{
    void M()
    {
        M()
    }
}
(5,12): error CS1002: ; expected
class C
{
    void M()
    {
        M()}
}
(5,10): error CS1002: ; expected

I think this happens because the SyntaxDiagnosticInfo is created with offset of -2 when the tree is parsed, which works correctly for the original tree. But when the whitespace is updated, the offset causes the incorrect location.

@jinujoseph
Copy link
Contributor

Possible duplicate of #23330

@jinujoseph jinujoseph added Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it Language-C# Area-Compilers and removed Area-IDE labels Nov 15, 2018
@gafter gafter added this to the Backlog milestone Jul 17, 2019
@doivosevic
Copy link

doivosevic commented Aug 27, 2020

Hey! I'm trying to repro this bug on master Commit hash: f09c4b7
and on my local Version 16.7.2 whichever Roslyn that is and it doesn't seem to repro

EDIT: My bad. Still repros

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it Language-C#
Projects
None yet
Development

No branches or pull requests

4 participants