diff --git a/evaluator/evaluator.go b/evaluator/evaluator.go index 758f4dd..313ed4a 100644 --- a/evaluator/evaluator.go +++ b/evaluator/evaluator.go @@ -45,7 +45,7 @@ func Eval(node ast.Node, env *object.Environment) object.Object { return left } right := Eval(node.Right, env) - if isError(right) { + if isError(right) && right != nil { return right } return evalInfixExpression(node.Operator, left, right, node.Token.Line) diff --git a/evaluator/infix.go b/evaluator/infix.go index f25ef9d..d11d867 100644 --- a/evaluator/infix.go +++ b/evaluator/infix.go @@ -8,6 +8,9 @@ import ( ) func evalInfixExpression(operator string, left, right object.Object, line int) object.Object { + if right == nil { + return newError("Mstari %d: Umekosea hapa", line) + } if left == nil { return newError("Mstari %d: Umekosea hapa", line) }