Skip to content

Commit

Permalink
Move to semantic pass
Browse files Browse the repository at this point in the history
  • Loading branch information
nwt committed Sep 29, 2023
1 parent be9ccad commit 7170e3e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 0 additions & 4 deletions compiler/kernel/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ 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 @@ -398,9 +397,6 @@ 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
9 changes: 9 additions & 0 deletions compiler/semantic/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,15 @@ func (a *analyzer) semExpr(e ast.Expr) (dag.Expr, error) {
Where: where,
}, nil
case *ast.RecordExpr:
fields := map[string]struct{}{}
var out []dag.RecordElem
for _, elem := range e.Elems {
switch elem := elem.(type) {
case *ast.Field:
if _, ok := fields[elem.Name]; ok {
return nil, fmt.Errorf("record expression: %w", &zed.DuplicateFieldError{Name: elem.Name})
}
fields[elem.Name] = struct{}{}
e, err := a.semExpr(elem.Value)
if err != nil {
return nil, err
Expand All @@ -169,6 +174,10 @@ func (a *analyzer) semExpr(e ast.Expr) (dag.Expr, error) {
Value: e,
})
case *ast.ID:
if _, ok := fields[elem.Name]; ok {
return nil, fmt.Errorf("record expression: %w", &zed.DuplicateFieldError{Name: elem.Name})
}
fields[elem.Name] = struct{}{}
v, err := a.semID(elem)
if err != nil {
return nil, err
Expand Down

0 comments on commit 7170e3e

Please sign in to comment.