Skip to content

Commit

Permalink
fixed if condition bug on non-existing variable
Browse files Browse the repository at this point in the history
  • Loading branch information
sio4 committed Oct 4, 2022
1 parent 73b2405 commit 0d35e96
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,11 @@ func (c *compiler) evalIdentifier(node *ast.Identifier) (interface{}, error) {

func (c *compiler) evalInfixExpression(node *ast.InfixExpression) (interface{}, error) {
lres, err := c.evalExpression(node.Left)
if err != nil && node.Operator != "==" && node.Operator != "!=" {
if err != nil &&
node.Operator != "==" && node.Operator != "!=" &&
node.Operator != "||" && node.Operator != "&&" {
return nil, err
} // nil lres is acceptable only for '==' and '!='
} // nil lres is acceptable only for '==', '!=', and logical operators

switch { // fast return
case node.Operator == "&&" && !c.isTruthy(lres):
Expand All @@ -447,9 +449,11 @@ func (c *compiler) evalInfixExpression(node *ast.InfixExpression) (interface{},
}

rres, err := c.evalExpression(node.Right)
if err != nil && node.Operator != "==" && node.Operator != "!=" {
if err != nil &&
node.Operator != "==" && node.Operator != "!=" &&
node.Operator != "||" && node.Operator != "&&" {
return nil, err
} // nil rres is acceptable only for '==' and '!='
} // nil rres is acceptable only for '==', '!=', and logical operators

switch node.Operator {
case "&&", "||":
Expand Down

0 comments on commit 0d35e96

Please sign in to comment.