From 717b51dbba41599e260fadc63ee98c83fa06cfb3 Mon Sep 17 00:00:00 2001 From: Matthew Nibecker Date: Wed, 4 Oct 2023 14:54:37 -0700 Subject: [PATCH] fixes --- compiler/semantic/expr.go | 70 ++++++++++----------------------------- compiler/semantic/op.go | 7 ++-- 2 files changed, 20 insertions(+), 57 deletions(-) diff --git a/compiler/semantic/expr.go b/compiler/semantic/expr.go index 037bec9ce5..804034bdae 100644 --- a/compiler/semantic/expr.go +++ b/compiler/semantic/expr.go @@ -440,37 +440,20 @@ func (a *analyzer) semPath(e ast.Expr) (*dag.Path, error) { if lhs == nil || err != nil { return nil, nil } - switch rhs := e.RHS.(type) { - case *ast.ID: - if ref, err := a.scope.LookupExpr(rhs.Name); err != nil { - return nil, err - } else if ref != nil { - l, ok := ref.(*dag.Literal) - if !ok { - return nil, nil - } - v, err := zson.ParseValue(a.zctx, l.Value) - if err != nil || zed.TypeUnder(v.Type) != zed.TypeString { - return nil, nil - } - lhs.Path = append(lhs.Path, &dag.StaticPathElem{Kind: "StaticPathElem", Name: v.AsString()}) - return lhs, nil - } - lhs.Path = append(lhs.Path, pathOf(rhs.Name)) - case *astzed.Primitive: - if rhs.Type != "string" { - return nil, nil - } - lhs.Path = append(lhs.Path, &dag.StaticPathElem{Kind: "StaticPathElem", Name: rhs.Text}) - default: - this := a.dotExprToFieldPath(e.RHS) - if this == nil { - return nil, nil - } + rhs, err := a.semExpr(e.RHS) + if err != nil { + return nil, err + } + if this, ok := rhs.(*dag.This); ok { lhs.Path = append(lhs.Path, this) + return lhs, nil + } + if p, ok := isStringConst(a.zctx, rhs); ok { + lhs.Path = append(lhs.Path, &dag.StaticPathElem{Kind: "StaticPathElem", Name: p}) + return lhs, nil } - return lhs, nil } + return nil, nil case *ast.ID: id, err := a.semID(e) if err != nil { @@ -739,32 +722,15 @@ func (a *analyzer) dotExprToFieldPath(e ast.Expr) *dag.This { if lhs == nil { return nil } - var name string - switch rhs := e.RHS.(type) { - case *ast.ID: - ref, err := a.scope.LookupExpr(rhs.Name) - if err != nil || ref == nil { - return nil - } - l, ok := ref.(*dag.Literal) - if !ok { - return nil - } - v, err := zson.ParseValue(a.zctx, l.Value) - if err != nil || zed.TypeUnder(v.Type) != zed.TypeString { - return nil - } - name = v.AsString() - case *astzed.Primitive: - if rhs.Type != "string" { - return nil - } - name = rhs.Text - default: + rhs, err := a.semExpr(e.RHS) + if err != nil { return nil } - lhs.Path = append(lhs.Path, name) - return lhs + if s, ok := isStringConst(a.zctx, rhs); ok { + lhs.Path = append(lhs.Path, s) + return lhs + } + return nil } case *ast.ID: o, err := a.semID(e) diff --git a/compiler/semantic/op.go b/compiler/semantic/op.go index d9f6fa50e0..117337cfa9 100644 --- a/compiler/semantic/op.go +++ b/compiler/semantic/op.go @@ -616,7 +616,7 @@ func (a *analyzer) semOp(o ast.Op, seq dag.Seq) (dag.Seq, error) { if err != nil { return nil, err } - // Check for what we can. + // We can do collision checking on static paths, so check what we can. var fields field.List for _, a := range assignments { if this := a.LHS.StaticPath(); this != nil { @@ -861,10 +861,7 @@ func (a *analyzer) singletonAgg(agg ast.Assignment, seq dag.Seq) dag.Seq { Kind: "Yield", } this := out.LHS.StaticPath() - if this == nil { - return nil - } - if len(out.LHS.Path) != 1 { + if this == nil || len(out.LHS.Path) != 1 { return nil } yield.Exprs = append(yield.Exprs, this)