diff --git a/builtin/builtin.go b/builtin/builtin.go index 9687d7e5..cc6f197c 100644 --- a/builtin/builtin.go +++ b/builtin/builtin.go @@ -487,7 +487,7 @@ var Builtins = []*Function{ return timeType, nil } if len(args) == 1 { - if args[0].AssignableTo(locationType) { + if args[0] != nil && args[0].AssignableTo(locationType) { return timeType, nil } } @@ -559,7 +559,7 @@ var Builtins = []*Function{ if len(args) < 1 { return anyType, fmt.Errorf("invalid number of arguments (expected at least 1, got %d)", len(args)) } - if args[0].AssignableTo(locationType) { + if args[0] != nil && args[0].AssignableTo(locationType) { args = args[1:] } if len(args) > 3 { diff --git a/builtin/builtin_test.go b/builtin/builtin_test.go index b7579153..b99ed42c 100644 --- a/builtin/builtin_test.go +++ b/builtin/builtin_test.go @@ -233,6 +233,9 @@ func TestBuiltin_errors(t *testing.T) { {`bitshr(-5, -2)`, "invalid operation: negative shift count -2 (type int) (1:1)"}, {`bitshl(1, -1)`, "invalid operation: negative shift count -1 (type int) (1:1)"}, {`bitushr(-5, -2)`, "invalid operation: negative shift count -2 (type int) (1:1)"}, + {`now(nil)`, "invalid number of arguments (expected 0, got 1)"}, + {`date(nil)`, "interface {} is nil, not string (1:1)"}, + {`timezone(nil)`, "interface {} is nil, not string (1:1)"}, } for _, test := range errorTests { t.Run(test.input, func(t *testing.T) {