Skip to content

Commit

Permalink
Fix panic compiling record expression with duplicate field
Browse files Browse the repository at this point in the history
Closes #3365.
  • Loading branch information
nwt committed Sep 29, 2023
1 parent f662ee1 commit be9ccad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compiler/kernel/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/brimdata/zed/runtime/op/traverse"
"github.com/brimdata/zed/zbuf"
"github.com/brimdata/zed/zson"
"golang.org/x/exp/slices"
"golang.org/x/text/unicode/norm"
)

Expand Down Expand Up @@ -397,6 +398,9 @@ func (b *Builder) compileRecordExpr(record *dag.RecordExpr) (expr.Evaluator, err
for _, elem := range record.Elems {
switch elem := elem.(type) {
case *dag.Field:
if slices.ContainsFunc(elems, func(r expr.RecordElem) bool { return r.Name == elem.Name }) {
return nil, fmt.Errorf("record expression: %w", &zed.DuplicateFieldError{Name: elem.Name})
}
e, err := b.compileExpr(elem.Value)
if err != nil {
return nil, err
Expand Down
3 changes: 3 additions & 0 deletions compiler/ztests/record-dup-field.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
zed: yield {x:1,x:2}

errorRE: 'record expression: duplicate field: "x"'

0 comments on commit be9ccad

Please sign in to comment.