Skip to content

Commit

Permalink
Merge pull request #80 from gekkowrld/fi
Browse files Browse the repository at this point in the history
Handle `nil` dereference in expressions
  • Loading branch information
AvicennaJr committed Mar 22, 2024
2 parents 3b2207a + 226d721 commit 7f69b77
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion evaluator/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions evaluator/infix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 7f69b77

Please sign in to comment.