Support converting operands to strings for the + operator
This commit is contained in:
parent
b31528d593
commit
5ff2f8be5a
1 changed files with 8 additions and 0 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue