diff --git a/expr.go b/expr.go index cbadbfc..442b8c8 100644 --- a/expr.go +++ b/expr.go @@ -55,13 +55,17 @@ func (t *Template) performOp(a, b reflect.Value, op ast.Operator) (any, error) { 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 !b.IsValid() { - if op.Value != "==" { - return nil, ast.PosError(op, "invalid operator for nil value (expected ==, got %s)", op.Value) + if op.Value != "==" && op.Value != "!=" { + return nil, ast.PosError(op, "invalid operator for nil value (expected == or !=, got %s)", op.Value) } switch a.Kind() { case reflect.Chan, reflect.Slice, reflect.Map, reflect.Func, reflect.Interface, reflect.Pointer: - return a.IsNil(), nil + if op.Value == "==" { + return a.IsNil(), nil + } else { + return !a.IsNil(), nil + } default: return nil, ast.PosError(op, "values of type %s cannot be compared against nil", a.Type()) }