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#: Object initializers referencing each other cause conversion error #1080

Open
GrahamTheCoder opened this issue Feb 24, 2024 · 0 comments
Labels
VB -> C# Specific to VB -> C# conversion

Comments

@GrahamTheCoder
Copy link
Member

GrahamTheCoder commented Feb 24, 2024

VB.Net input code

Imports System.Drawing

Public Class VisualBasicClass
    Public Sub M()
        Dim Shape = New Point() With {
        .X = 1,
        .Y = .X
        }
    End Sub
End Class

Erroneous output

using System.Drawing;

public partial class VisualBasicClass
{
    public void M()
    {
        Point @init = new Point();
        var Shape = (@init.X = 1, @init.Y = default
#error Cannot convert MemberAccessExpressionSyntax - see comment for details
  /* Cannot convert MemberAccessExpressionSyntax, System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
      at System.ThrowHelper.ThrowKeyNotFoundException()
      at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
      at ICSharpCode.CodeConverter.CSharp.ExpressionNodeVisitor.<VisitMemberAccessExpression>d__53.MoveNext() in C:\Users\gph77\source\repos\CodeConverter\CodeConverter\CSharp\ExpressionNodeVisitor.cs:line 435
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at ICSharpCode.CodeConverter.CSharp.CommentConvertingVisitorWrapper.<ConvertHandledAsync>d__12`1.MoveNext() in C:\Users\gph77\source\repos\CodeConverter\CodeConverter\CSharp\CommentConvertingVisitorWrapper.cs:line 40

   Input:
   .X

    */, @init).@init;
    }
}System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.ThrowHelper.ThrowKeyNotFoundException()
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at ICSharpCode.CodeConverter.CSharp.ExpressionNodeVisitor.<VisitMemberAccessExpression>d__53.MoveNext() in C:\Users\gph77\source\repos\CodeConverter\CodeConverter\CSharp\ExpressionNodeVisitor.cs:line 435
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at ICSharpCode.CodeConverter.CSharp.CommentConvertingVisitorWrapper.<ConvertHandledAsync>d__12`1.MoveNext() in C:\Users\gph77\source\repos\CodeConverter\CodeConverter\CSharp\CommentConvertingVisitorWrapper.cs:line 40

Expected output

using System.Drawing;

public partial class VisualBasicClass
{
    public void M()
    {
        Point @init = new Point();
        var Shape = (@init.X = 1, @init.Y = @init.X, @init).@init;
    }
}

Details

  • Product in use: 18e8526 new unit test

This is due to only handling one of the types of collection initializers

@GrahamTheCoder GrahamTheCoder added the VB -> C# Specific to VB -> C# conversion label Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
VB -> C# Specific to VB -> C# conversion
Projects
None yet
Development

No branches or pull requests

1 participant