Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mattnibs committed Oct 4, 2023
1 parent fd090de commit 717b51d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 57 deletions.
70 changes: 18 additions & 52 deletions compiler/semantic/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 2 additions & 5 deletions compiler/semantic/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 717b51d

Please sign in to comment.