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#: Cannot convert InvocationExpressionSyntax, System.ArgumentNullException: Value cannot be null. #673

Closed
ATECoder opened this issue Oct 28, 2020 · 1 comment
Labels
exception caught An exception is caught (and stacktrace provided) good first issue regression Something that used to work VB -> C# Specific to VB -> C# conversion

Comments

@ATECoder
Copy link

Input code

        Public Shared Sub Identify(ByVal talker As ITraceMessageTalker)
            talker?.IdentifyTalker(IdentityTraceMessage())
        End Sub

Erroneous output

        public static void Identify(ITraceMessageTalker talker)
        {
            ;
#error Cannot convert ExpressionStatementSyntax - see comment for details
            /* Cannot convert InvocationExpressionSyntax, System.ArgumentNullException: Value cannot be null.
            Parameter name: node
               at Microsoft.CodeAnalysis.VisualBasic.VBSemanticModel.GetSymbolInfoForNode(SyntaxNode node, CancellationToken cancellationToken)
               at Microsoft.CodeAnalysis.VisualBasic.VBSemanticModel.GetSymbolInfoCore(SyntaxNode node, CancellationToken cancellationToken)
               at ICSharpCode.CodeConverter.CSharp.ExpressionNodeVisitor.MayThrow(ExpressionSyntax expression)
               at ICSharpCode.CodeConverter.CSharp.ExpressionNodeVisitor.FirstArgDefinitelyEvaluated(InvocationExpressionSyntax parentInvocation)
               at ICSharpCode.CodeConverter.CSharp.ExpressionNodeVisitor.DefinitelyExecutedAfterPreviousStatement(InvocationExpressionSyntax invocation)
               at ICSharpCode.CodeConverter.CSharp.ExpressionNodeVisitor.RequiresLocalFunction(InvocationExpressionSyntax invocation, IMethodSymbol invocationSymbol)
               at ICSharpCode.CodeConverter.CSharp.ExpressionNodeVisitor.<VisitInvocationExpression>d__77.MoveNext()
            --- End of stack trace from previous location where exception was thrown ---
               at ICSharpCode.CodeConverter.CSharp.CommentConvertingVisitorWrapper.<ConvertHandledAsync>d__5`1.MoveNext()

            Input: Global.isr.Algorithms.Signals.My.MyLibrary.IdentityTraceMessage()
            Context:
                        talker?.IdentifyTalker(Global.isr.Algorithms.Signals.My.MyLibrary.IdentityTraceMessage())

             */
        }

Expected output

        public static void Identify(ITraceMessageTalker talker)
        {
            talker?.IdentifyTalker( global::isr.Algorithms.Signals.My.MyLibrary.IdentityTraceMessage() );
        }

or
        public static void Identify(ITraceMessageTalker talker)
        {
            talker?.IdentifyTalker( IdentityTraceMessage() );
        }

Details

  • Product in use: codeconverter.icsharpcode.net / VS extension
  • Version in use: 8.1.8.0 artifact of 10/12
  • Did you see it working in a previous version, which? N/A
  • Any other relevant information to the issue, or your interest in contributing a fix.

This seems to be an issue with the Global. vs. global:: conversion. Was the artifact addressing the Global syntax?

@ATECoder ATECoder added the VB -> C# Specific to VB -> C# conversion label Oct 28, 2020
@GrahamTheCoder
Copy link
Member

Thanks, I can reproduce the issue when converting this minimal compilable unit of VB without any other context:

Imports System

Public Class AClass
        Public Shared Sub Identify(ByVal talker As ITraceMessageTalker)
            talker?.IdentifyTalker(IdentityTraceMessage())
        End Sub

    Private Shared Function IdentityTraceMessage() As Object
        Throw New NotImplementedException()
    End Function
End Class

Public Interface ITraceMessageTalker
    Function IdentifyTalker(v As Object) As Object
End Interface

The simplest fix would be just to return true if there's no symbol here:

private bool MayThrow(VBSyntax.ExpressionSyntax expression)
{
expression = expression.SkipIntoParens();
if (expression is VBSyntax.InstanceExpressionSyntax) return false;
var symbol = _semanticModel.GetSymbolInfo(expression).Symbol;
return !symbol.IsKind(SymbolKind.Local) && !symbol.IsKind(SymbolKind.Field);
}

@GrahamTheCoder GrahamTheCoder added compilation error A bug where the converted output won't compile good first issue regression Something that used to work labels Oct 28, 2020
@GrahamTheCoder GrahamTheCoder added exception caught An exception is caught (and stacktrace provided) and removed compilation error A bug where the converted output won't compile labels Oct 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exception caught An exception is caught (and stacktrace provided) good first issue regression Something that used to work VB -> C# Specific to VB -> C# conversion
Projects
None yet
Development

No branches or pull requests

2 participants