check whether the types of the operants of an equality expression can combine instead of enforcing them to both be integers

This commit is contained in:
2020-02-03 23:45:52 +01:00
parent e8f80eb2f9
commit f3c5bac860

View File

@@ -295,9 +295,10 @@ public class ContextAnalysis extends KlangBaseVisitor<Node> {
int line = ctx.start.getLine(); int line = ctx.start.getLine();
int col = ctx.start.getCharPositionInLine(); int col = ctx.start.getCharPositionInLine();
if (lhs.type != Type.getIntegerType() || rhs.type != Type.getIntegerType()) { try {
String error = "Both operants of this expression have to be a number."; lhs.type.combine(rhs.type);
throw new RuntimeException(Helper.getErrorPrefix(line, col) + error); } catch (Exception e) {
throw new RuntimeException(Helper.getErrorPrefix(line, col) + e.getMessage());
} }
EqualityExpression result = new EqualityExpression((Expression) lhs, (Expression) rhs); EqualityExpression result = new EqualityExpression((Expression) lhs, (Expression) rhs);