Skip to content

Commit 7f69b77

Browse files
authored
Merge pull request #80 from gekkowrld/fi
Handle `nil` dereference in expressions
2 parents 3b2207a + 226d721 commit 7f69b77

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

evaluator/evaluator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func Eval(node ast.Node, env *object.Environment) object.Object {
4545
return left
4646
}
4747
right := Eval(node.Right, env)
48-
if isError(right) {
48+
if isError(right) && right != nil {
4949
return right
5050
}
5151
return evalInfixExpression(node.Operator, left, right, node.Token.Line)

evaluator/infix.go

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import (
88
)
99

1010
func evalInfixExpression(operator string, left, right object.Object, line int) object.Object {
11+
if right == nil {
12+
return newError("Mstari %d: Umekosea hapa", line)
13+
}
1114
if left == nil {
1215
return newError("Mstari %d: Umekosea hapa", line)
1316
}

0 commit comments

Comments
 (0)