From 8b68b284c04e160bc1587680efee5ecc262b1d0c Mon Sep 17 00:00:00 2001 From: pmqueiroz Date: Tue, 3 Dec 2024 10:14:12 -0300 Subject: [PATCH] feat: compare enums --- interpreter/eval.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/interpreter/eval.go b/interpreter/eval.go index df22c29..b7825e7 100644 --- a/interpreter/eval.go +++ b/interpreter/eval.go @@ -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: