fix(vm): handle non-comparable groupBy keys by thevilledev · Pull Request #940 · expr-lang/expr · GitHub
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
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
Loading