Skip to content

Commit

Permalink
feat: compare enums
Browse files Browse the repository at this point in the history
  • Loading branch information
pmqueiroz committed Dec 3, 2024
1 parent 6427cf0 commit 8b68b28
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion interpreter/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,26 @@ func Evaluate(expression ast.Expression, env *environment.Environment) (interfac
}
return leftVal <= rightVal, nil
case tokens.EQUAL_EQUAL:
return left == right, nil
switch leftVal := left.(type) {
case ast.EnumMember:
if rightVal, ok := right.(ast.EnumMember); ok {
if leftVal.Signature == rightVal.Signature && leftVal.Name == rightVal.Name {
for i, arg := range leftVal.Arguments {
if arg.Value != rightVal.Arguments[i].Value {
return false, nil
}
}

return true, nil
}

return false, nil
}

return nil, exception.NewRuntimeError("RT026", types.SafeParseUmbraType(left), types.SafeParseUmbraType(right))
default:
return left == right, nil
}
case tokens.BANG_EQUAL:
return left != right, nil
default:
Expand Down

0 comments on commit 8b68b28

Please sign in to comment.