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 5a9c67b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,14 @@ children:
range: 11:16 - 11:24
dataflow_sources:
- 80
- 83
- 84
- 85
queries:
- 4
children:
- type: variable_name
id: 80
range: 11:16 - 11:21
alias_of:
- 27
children:
- type: '"$"'
id: 81
Expand Down

0 comments on commit 5a9c67b

Please sign in to comment.