diff --git a/builtin/builtin.go b/builtin/builtin.go index 87e73614..774a13d6 100644 --- a/builtin/builtin.go +++ b/builtin/builtin.go @@ -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 diff --git a/builtin/builtin_test.go b/builtin/builtin_test.go index 0d0dec35..5797d1d2 100644 --- a/builtin/builtin_test.go +++ b/builtin/builtin_test.go @@ -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) { diff --git a/test/fuzz/fuzz_test.go b/test/fuzz/fuzz_test.go index e12c4d8e..7ae797e7 100644 --- a/test/fuzz/fuzz_test.go +++ b/test/fuzz/fuzz_test.go @@ -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()