fix: 部分代码嵌套模式数不正确的问题

This commit is contained in:
zhangxun 2025-06-27 13:18:03 +08:00
parent 43fd1d175d
commit 237c35f0a0
2 changed files with 9 additions and 6 deletions

View File

@ -66,12 +66,12 @@ public class StatementBuilder {
buildIf(ifNode); buildIf(ifNode);
return; return;
} }
if (stmt instanceof ExpressionStatementNode(ExpressionNode exp)) { if (stmt instanceof ExpressionStatementNode(ExpressionNode exp, _, _, _)) {
// 纯表达式语句 foo(); // 纯表达式语句 foo();
expr.build(exp); expr.build(exp);
return; return;
} }
if (stmt instanceof AssignmentNode(String var, ExpressionNode rhs)) { if (stmt instanceof AssignmentNode(String var, ExpressionNode rhs, _, _, _)) {
// 赋值语句 a = b + 1; // 赋值语句 a = b + 1;
final String type = ctx.getScope().lookupType(var); final String type = ctx.getScope().lookupType(var);
@ -208,7 +208,10 @@ public class StatementBuilder {
if (cond instanceof BinaryExpressionNode( if (cond instanceof BinaryExpressionNode(
ExpressionNode left, ExpressionNode left,
String operator, String operator,
ExpressionNode right ExpressionNode right,
_,
_,
_
) )
&& ComparisonUtils.isComparisonOperator(operator)) { && ComparisonUtils.isComparisonOperator(operator)) {

View File

@ -51,8 +51,8 @@ public class CallExpressionAnalyzer implements ExpressionAnalyzer<CallExpression
ExpressionNode callee = call.callee(); ExpressionNode callee = call.callee();
// 支持模块调用形式ModuleName.FunctionName(...) // 支持模块调用形式ModuleName.FunctionName(...)
if (callee instanceof MemberExpressionNode(var obj, String member) if (callee instanceof MemberExpressionNode(var obj, String member, _, _, _)
&& obj instanceof IdentifierNode(String mod)) { && obj instanceof IdentifierNode(String mod, _, _, _)) {
// 验证模块是否存在并已导入 // 验证模块是否存在并已导入
if (!ctx.getModules().containsKey(mod) if (!ctx.getModules().containsKey(mod)
|| (!mi.getImports().contains(mod) && !mi.getName().equals(mod))) { || (!mi.getImports().contains(mod) && !mi.getName().equals(mod))) {
@ -65,7 +65,7 @@ public class CallExpressionAnalyzer implements ExpressionAnalyzer<CallExpression
functionName = member; functionName = member;
// 简单函数名形式func(...) // 简单函数名形式func(...)
} else if (callee instanceof IdentifierNode(String name)) { } else if (callee instanceof IdentifierNode(String name, _, _, _)) {
functionName = name; functionName = name;
// 不支持的 callee 形式 // 不支持的 callee 形式