From f3c5bac8606fde99dc409214f596ec1b352c51e3 Mon Sep 17 00:00:00 2001 From: nitrix Date: Mon, 3 Feb 2020 23:45:52 +0100 Subject: [PATCH] check whether the types of the operants of an equality expression can combine instead of enforcing them to both be integers --- src/main/java/de/hsrm/compiler/Klang/ContextAnalysis.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/hsrm/compiler/Klang/ContextAnalysis.java b/src/main/java/de/hsrm/compiler/Klang/ContextAnalysis.java index 9b20bf9..5091dc1 100644 --- a/src/main/java/de/hsrm/compiler/Klang/ContextAnalysis.java +++ b/src/main/java/de/hsrm/compiler/Klang/ContextAnalysis.java @@ -295,9 +295,10 @@ public class ContextAnalysis extends KlangBaseVisitor { int line = ctx.start.getLine(); int col = ctx.start.getCharPositionInLine(); - if (lhs.type != Type.getIntegerType() || rhs.type != Type.getIntegerType()) { - String error = "Both operants of this expression have to be a number."; - throw new RuntimeException(Helper.getErrorPrefix(line, col) + error); + try { + lhs.type.combine(rhs.type); + } catch (Exception e) { + throw new RuntimeException(Helper.getErrorPrefix(line, col) + e.getMessage()); } EqualityExpression result = new EqualityExpression((Expression) lhs, (Expression) rhs);