icsharpcode / CodeConverter

Convert code from C# to VB.NET and vice versa using Roslyn
https://icsharpcode.github.io/CodeConverter/
MIT License
826 stars 216 forks source link

VB -> C#: comments/trivia in wrong location #1095

Closed TymurGubayev closed 2 months ago

TymurGubayev commented 5 months ago

VB.Net input code

    'a
    Property P(i As Integer)
        'b
        Get
            '1
            Dim x = 1 '2
            '3
        End Get

        'c
        Set(value)
            '4
            Dim x = 1 '5
            '6
            x = value + i '7
            '8
        End Set
        'd
    End Property

Erroneous output

        // a
        // b
        public void get_P(int i)
        {
            // 1
            int x = 1; // 2
            return default(object);
            // 3

            // c
            // 4
            // 6
            // 8
            // d
        } // 5
          // 7

        public void set_P(int i, void value)
        {
            int x = 1;
            x = Conversions.ToInteger(Operators.AddObject(value, i));
        }

Expected output

        // a
        public void get_P(int i)
        // b
        {
            // 1
            int x = 1; // 2
            return default(object);
            // 3
        }

        // c
        public void set_P(int i, void value)
        {
            // 4
            int x = 1; // 5
            // 6
            x = Conversions.ToInteger(Operators.AddObject(value, i)); // 7
            // 8
        }
        // d

This only affects trivia, so the code isn't actually broken, and as far as I can tell no comment is lost, but there is loss of information nonetheless: it's impossible to map the comments to the statements they belong to.

Details

Related issues coalesced

https://github.com/icsharpcode/CodeConverter/issues/1098

TymurGubayev commented 2 months ago

mostly fixed in #1117, further improvement is a different issue (the // d-comment is inside the setter instead of just after it)