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

VB -> C#: Mapping trivia from source can override any #error trivia added by Converter #917

Closed
Yozer opened this issue Jul 6, 2022 · 2 comments · Fixed by #919
Closed
Labels
output logic error A bug where the converted output behaves differently to the input code VB -> C# Specific to VB -> C# conversion

Comments

@Yozer
Copy link
Member

Yozer commented Jul 6, 2022

VB.Net input code

Public Class VisualBasicClass
    Public Class TestClass
        Public Property A As Integer
        Public Property B As integer
    End class
   Public Sub New()
        Dim y As  New TestClass() With { .A = 1, .B = .A 
        }
   End Sub
End Class

Erroneous output

public VisualBasicClass()
{
    var y = new TestClass()
    {
        A = 1,// test
        B = default
    };
}

Expected output

public VisualBasicClass()
{
    var y = new TestClass()
    {
        A = 1,// test
        B = default
        #error bla bla, can't convert this code
    };
}

If you move } to the same line:
Dim y As New TestClass() With { .A = 1, .B = .A }
then the conversion looks "ok".
It think TriviaMapper will override any trivia added by the converter when there is something other we want to map from the source vb code.
What's worse, you will not get any info about errors in the output window (why dummyNode doesn't have error annotations?)

Details

  • Product in use: e.g. codeconverter.icsharpcode.net / VS extension / both
  • Version in use: e.g. 5.6.3 or a commit hash (if it's a 3rd party tool using this library, try one of the above)
  • Did you see it working in a previous version, which?
  • Any other relevant information to the issue, or your interest in contributing a fix.
@Yozer Yozer added output logic error A bug where the converted output behaves differently to the input code VB -> C# Specific to VB -> C# conversion labels Jul 6, 2022
@Yozer
Copy link
Member Author

Yozer commented Jul 6, 2022

Worked fine before #880
I guess we could annate error trivia added by the converter and carry it over to C# code?

@GrahamTheCoder
Copy link
Member

Ah yeah, I think it just overwrites whatever's there, which is pretty bad in the error case!

It'd be possible to just avoid overwriting, but then you'd have to pay attention to balancing the trivia. To get that for free, it may be better in the LineTriviaMapper, to pre-populate trivia collections with any warning/error trivias from the converted tree.
You'd probably need to change them to be converted before going into the collection for consistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
output logic error A bug where the converted output behaves differently to the input code VB -> C# Specific to VB -> C# conversion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants