summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/craftinginterpreters/lox/Interpreter.java8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/com/craftinginterpreters/lox/Interpreter.java b/src/com/craftinginterpreters/lox/Interpreter.java
index 24cf1c0..57e697c 100644
--- a/src/com/craftinginterpreters/lox/Interpreter.java
+++ b/src/com/craftinginterpreters/lox/Interpreter.java
@@ -110,6 +110,14 @@ class Interpreter implements Expr.Visitor<Object> {
return (String) left + (String) right;
}
+ if (left instanceof String) {
+ return (String) left + stringify(right);
+ }
+
+ if (right instanceof String) {
+ return stringify(left) + (String) right;
+ }
+
throw new RuntimeError(expr.operator, "Operands must be two numbers or two strings.");
case SLASH:
checkNumberOperands(expr.operator, left, right);