Skip to content

Commit e43eba1

Browse files
committed
fix ConditionalExpression when Condition part is BinaryExpressionSyntax
1 parent 4366966 commit e43eba1

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

CSharp.lua/LuaSyntaxNodeTransfor.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2597,9 +2597,14 @@ public override LuaSyntaxNode VisitConditionalExpression(ConditionalExpressionSy
25972597
CurBlock.Statements.Add(ifStatement);
25982598
return temp;
25992599
} else {
2600-
var condition = (LuaExpressionSyntax)node.Condition.Accept(this);
2601-
var whenTrue = (LuaExpressionSyntax)node.WhenTrue.Accept(this);
2602-
var whenFalse = (LuaExpressionSyntax)node.WhenFalse.Accept(this);
2600+
LuaExpressionSyntax Accept(ExpressionSyntax expressionNode) {
2601+
var expression = (LuaExpressionSyntax)expressionNode.Accept(this);
2602+
return expressionNode is BinaryExpressionSyntax ? new LuaParenthesizedExpressionSyntax(expression) : expression;
2603+
}
2604+
2605+
var condition = Accept(node.Condition);
2606+
var whenTrue = Accept(node.WhenTrue);
2607+
var whenFalse = Accept(node.WhenFalse);
26032608
return new LuaBinaryExpressionSyntax(new LuaBinaryExpressionSyntax(condition, LuaSyntaxNode.Tokens.And, whenTrue), LuaSyntaxNode.Tokens.Or, whenFalse);
26042609
}
26052610
}

0 commit comments

Comments
 (0)