Skip to content

Commit b22e6c9

Browse files
EddieEddie
authored andcommitted
feat: graceful if statement expression error
1 parent b384be3 commit b22e6c9

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

out/artifacts/jungle_jar/jungle.jar

90 Bytes
Binary file not shown.

src/main/java/com/jungle/compiler/visitor/IfVisitor.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ protected void visit(
100100
throw new Error("expected if condition/expression");
101101
}
102102

103-
getExpressionVisitor().visit(mv, conditionNode, context);
103+
try {
104+
getExpressionVisitor().visit(mv, conditionNode, context);
105+
} catch (Throwable t) {
106+
throw new Error("if condition/expression is not resolvable", t);
107+
}
104108
if (!OperandType.INTEGER_OPERATION_TYPES.contains(context.peek())) {
105109
throw new Error("if condition/expression expected to be within the integer category");
106110
}

src/main/java/com/jungle/compiler/visitor/NumericOperatorVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public void visit(
130130
case OPERATOR_MULTIPLY: mv.visitInsn(operandType.getMultiplyOpcode()); break;
131131
case OPERATOR_DIVIDE: mv.visitInsn(operandType.getDivideOpcode()); break; // order matters
132132
case OPERATOR_MODULO: mv.visitInsn(operandType.getModuloOpcode()); break; // order matters
133-
default: throw new Error("unhandled binary operator " + ast);
133+
default: throw new Error("unhandled operation " + ast);
134134
}
135135
}
136136
}

0 commit comments

Comments
 (0)