Skip to content

Commit

Permalink
fix(php): lookup variables in subscript indices
Browse files Browse the repository at this point in the history
  • Loading branch information
didroe committed Oct 10, 2023
1 parent 6689428 commit 28838d9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions internal/languages/php/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func (analyzer *analyzer) Analyze(node *sitter.Node, visitChildren func() error)
return visitChildren()
case "dynamic_variable_name":
return analyzer.analyzeDynamicVariableName(node, visitChildren)
case "subscript_expression":
return analyzer.analyzeSubscript(node, visitChildren)
case "binary_expression",
"unary_op_expression",
"argument",
Expand Down Expand Up @@ -178,6 +180,17 @@ func (analyzer *analyzer) analyzeDynamicVariableName(node *sitter.Node, visitChi
return visitChildren()
}

// foo["bar"]
func (analyzer *analyzer) analyzeSubscript(node *sitter.Node, visitChildren func() error) error {
object := node.NamedChild(0)
analyzer.builder.Dataflow(node, object)
analyzer.lookupVariable(object)

analyzer.lookupVariable(node.NamedChild(1))

return visitChildren()
}

// default analysis, where the children are assumed to be aliases
func (analyzer *analyzer) analyzeGenericConstruct(node *sitter.Node, visitChildren func() error) error {
analyzer.builder.Alias(node, analyzer.builder.ChildrenFor(node)...)
Expand Down

0 comments on commit 28838d9

Please sign in to comment.