Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,9 @@ var Builtins = []*Function{
}
key := pair.Index(0)
value := pair.Index(1)
if k := key.Interface(); k != nil && !reflect.TypeOf(k).Comparable() {
return nil, fmt.Errorf("cannot use %T as a key for fromPairs: type is not comparable", k)
}
out.SetMapIndex(key, value)
}
return out.Interface(), nil
Expand Down
1 change: 1 addition & 0 deletions builtin/builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ func TestBuiltin_errors(t *testing.T) {
{`flatten([1, 2], [3, 4])`, "invalid number of arguments (expected 1, got 2)"},
{`flatten(1)`, "cannot flatten int"},
{`fromJSON("5e2482")`, "cannot unmarshal number"},
{`fromPairs([[[1, 2], 3]])`, "cannot use []interface {} as a key for fromPairs: type is not comparable"},
}
for _, test := range errorTests {
t.Run(test.input, func(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions test/fuzz/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func FuzzExpr(f *testing.F) {
regexp.MustCompile(`invalid order .*, expected asc or desc`),
regexp.MustCompile(`unknown order, use asc or desc`),
regexp.MustCompile(`cannot use .* as a key for groupBy: type is not comparable`),
regexp.MustCompile(`cannot use .* as a key for fromPairs: type is not comparable`),
}

env := NewEnv()
Expand Down