From c5470a45dd84c118373fc70ef9614157b2f5d8da Mon Sep 17 00:00:00 2001 From: Elara6331 Date: Thu, 6 Jun 2024 19:12:59 -0700 Subject: [PATCH] Define the behavior of nil better --- expr.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/expr.go b/expr.go index 442b8c8..a668eb9 100644 --- a/expr.go +++ b/expr.go @@ -54,6 +54,10 @@ func (t *Template) performOp(a, b reflect.Value, op ast.Operator) (any, error) { default: return nil, ast.PosError(op, "the in operator can only be used on strings, arrays, and slices (got %s and %s)", a.Type(), b.Type()) } + } else if !a.IsValid() && !b.IsValid() { + return true, nil + } else if !a.IsValid() { + return nil, ast.PosError(op, "nil must be on the right side of an expression") } else if !b.IsValid() { if op.Value != "==" && op.Value != "!=" { return nil, ast.PosError(op, "invalid operator for nil value (expected == or !=, got %s)", op.Value)