You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Error processing ICSharpCode.CodeConverter\CSharp\CompilationErrorFixer.cs
In 'C:\Users\Graham\Documents\GitHub\CodeConverter\ICSharpCode.CodeConverter\CSharp\CompilationErrorFixer.cs':
System.NotImplementedException: Cannot convert IsPatternExpressionSyntax from 'potentiallyRewrittenNode is...' at character 962
in '('
at ICSharpCode.CodeConverter.VB.CSharpConverter.MethodBodyVisitor.DefaultVisit(SyntaxNode node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1.VisitIsPatternExpression(IsPatternExpressionSyntax node)
at Microsoft.CodeAnalysis.CSharp.Syntax.IsPatternExpressionSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1.Visit(SyntaxNode node)
at ICSharpCode.CodeConverter.VB.CommentConvertingMethodBodyVisitor.DefaultVisit(SyntaxNode node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1.VisitIsPatternExpression(IsPatternExpressionSyntax node)
at Microsoft.CodeAnalysis.CSharp.Syntax.IsPatternExpressionSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1.Visit(SyntaxNode node)
at ICSharpCode.CodeConverter.VB.CSharpConverter.NodesVisitor.DefaultVisit(SyntaxNode node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1.VisitIsPatternExpression(IsPatternExpressionSyntax node)
at Microsoft.CodeAnalysis.CSharp.Syntax.IsPatternExpressionSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1.Visit(SyntaxNode node)
at ICSharpCode.CodeConverter.VB.CommentConvertingNodesVisitor.DefaultVisit(SyntaxNode node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1.VisitIsPatternExpression(IsPatternExpressionSyntax node)
at Microsoft.CodeAnalysis.CSharp.Syntax.IsPatternExpressionSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor)
at ICSharpCode.CodeConverter.VB.CSharpConverter.NodesVisitor.VisitParenthesizedExpression(ParenthesizedExpressionSyntax node)
at Microsoft.CodeAnalysis.CSharp.Syntax.ParenthesizedExpressionSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1.Visit(SyntaxNode node)
at ICSharpCode.CodeConverter.VB.CommentConvertingNodesVisitor.DefaultVisit(SyntaxNode node)
...
Option 1 - duplicate expression
The easiest way to convert this is probably to replace usages of the newly declared name with a cast of the original expression. Though this means the same (potentially expensive or even state-changing) expression may be evaluated multiple times and the repeated cast will look ugly and perform slightly worse.
Option 2 - hoist initialization
The alternative is to hoist the declaration and assignment out the front with a TryCast. With this solution there's potential for evaluating an expression that would not otherwise be evaluated, so if it's used in an else if, that would need to ideally turn into something like
Can't do exactly this because VB doesn't allow inline assignment, but we already have a mechanism for doing inline assignment with a helper method.
Option 4 - use local lazy/func
Hoist the declaration and initialization out the front as a Lazy. This ensures it's only evaluated once at the point it's required, though looks a little clunky:
Make use of inline assignment helper method with option 3, and the soution to #62
This should give the neatest result at the call site that's closest to matching the C#, and the easiest to refactor from (vs hoisting more of the cast into another helper method).
It'd also be good to ensure the variable declaration is assigned Nothing to avoid compiler warnings. __Assign's formal parameter should probably also be marked with <Out>, even though the above directly goes against that - this is necessary due to the VB compiler generating a warning irrespective of <Out>dotnet/vblang#67
The text was updated successfully, but these errors were encountered:
Option 1 - duplicate expression
The easiest way to convert this is probably to replace usages of the newly declared name with a cast of the original expression. Though this means the same (potentially expensive or even state-changing) expression may be evaluated multiple times and the repeated cast will look ugly and perform slightly worse.
Option 2 - hoist initialization
The alternative is to hoist the declaration and assignment out the front with a
TryCast
. With this solution there's potential for evaluating an expression that would not otherwise be evaluated, so if it's used in anelse if
, that would need to ideally turn into something likeOption 3 - hoist declaration, inline initialization
Hoist just the variable declaration out of the block, and assign to it in the expression:
Can't do exactly this because VB doesn't allow inline assignment, but we already have a mechanism for doing inline assignment with a helper method.
Option 4 - use local lazy/func
Hoist the declaration and initialization out the front as a
Lazy
. This ensures it's only evaluated once at the point it's required, though looks a little clunky:Similarly VB has the ability to declare inline functions which pass by reference which means it can actually assign the
casted
variableProposal
Make use of inline assignment helper method with option 3, and the soution to #62
This should give the neatest result at the call site that's closest to matching the C#, and the easiest to refactor from (vs hoisting more of the cast into another helper method).
It'd also be good to ensure the variable declaration is assigned
Nothing
to avoid compiler warnings.__Assign
's formal parameter should probably also be marked with<Out>
, even though the above directly goes against that - this is necessary due to the VB compiler generating a warning irrespective of<Out>
dotnet/vblang#67The text was updated successfully, but these errors were encountered: