Skip to content

Commit

Permalink
fix several panics
Browse files Browse the repository at this point in the history
Updates #23

Signed-off-by: Iskander Sharipov <[email protected]>
  • Loading branch information
quasilyte committed Aug 14, 2019
1 parent 947adbb commit b5c6a41
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
22 changes: 22 additions & 0 deletions matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,18 @@ func (m *matcher) eqNode(x, y node.Node) bool {
y, ok := y.(*stmt.StmtList)
return ok && m.eqNodeSlice(x.Stmts, y.Stmts)

case *stmt.Function:
return false // FIXME #23
case *stmt.Interface:
return false // FIXME #23
case *stmt.Class:
return false // FIXME #23
case *stmt.Trait:
return false // FIXME #23

case *stmt.InlineHtml:
y, ok := y.(*stmt.InlineHtml)
return ok && x.Value == y.Value
case *stmt.StaticVar:
y, ok := y.(*stmt.StaticVar)
return ok && m.eqNode(x.Variable, y.Variable) && m.eqNode(x.Expr, y.Expr)
Expand Down Expand Up @@ -247,6 +259,16 @@ func (m *matcher) eqNode(x, y node.Node) bool {
m.eqNodeSlice(x.Catches, y.Catches) &&
m.eqNode(x.Finally, y.Finally)

case *expr.ShortList:
y, ok := y.(*expr.ShortList)
return ok && m.eqNodeSlice(x.Items, y.Items)
case *expr.Yield:
y, ok := y.(*expr.Yield)
return ok && m.eqNode(x.Key, y.Key) && m.eqNode(x.Value, y.Value)
case *expr.YieldFrom:
y, ok := y.(*expr.YieldFrom)
return ok && m.eqNode(x.Expr, y.Expr)

case *expr.InstanceOf:
y, ok := y.(*expr.InstanceOf)
return ok && m.eqNode(x.Expr, y.Expr) && m.eqNode(x.Class, y.Class)
Expand Down
4 changes: 4 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ func parsePHP7expr(code []byte) (node.Node, []byte, error) {
if err != nil {
return nil, code, err
}
stmts := root.(*node.Root).Stmts
if len(stmts) == 0 {
return &stmt.Nop{}, code, nil
}
return root.(*node.Root).Stmts[0], code, nil
}

Expand Down

0 comments on commit b5c6a41

Please sign in to comment.