Skip to content
Merged
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
1 change: 1 addition & 0 deletions test/fuzz/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func FuzzExpr(f *testing.F) {
regexp.MustCompile(`sortBy order argument must be a string`),
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`),
}

env := NewEnv()
Expand Down
3 changes: 3 additions & 0 deletions vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,9 @@ func (vm *VM) Run(program *Program, env any) (_ any, err error) {
case OpGroupBy:
scope := vm.currScope
key := vm.pop()
if key != nil && !reflect.TypeOf(key).Comparable() {
panic(fmt.Sprintf("cannot use %T as a key for groupBy: type is not comparable", key))
}
scope.Acc.(groupBy)[key] = append(scope.Acc.(groupBy)[key], scope.Item())

case OpSortBy:
Expand Down
5 changes: 5 additions & 0 deletions vm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,11 @@ func TestVM_GroupAndSortOperations(t *testing.T) {
"odd": {1, 3, 5},
},
},
{
name: "group by with non-comparable key",
expr: `groupBy([1, 2, 3], [#, # + 1])`, // predicate returns a slice, which is not comparable
expectError: "not comparable",
},
{
name: "invalid sort order",
expr: `sortBy([1, 2, 3], #, "invalid")`,
Expand Down
Loading