From 28838d9bc87e6a09b302f07b41f7d3245b1d49af Mon Sep 17 00:00:00 2001 From: David Roe Date: Tue, 10 Oct 2023 11:30:53 +0100 Subject: [PATCH] fix(php): lookup variables in subscript indices --- internal/languages/php/analyzer/analyzer.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/internal/languages/php/analyzer/analyzer.go b/internal/languages/php/analyzer/analyzer.go index 6669c5056..803adaddb 100644 --- a/internal/languages/php/analyzer/analyzer.go +++ b/internal/languages/php/analyzer/analyzer.go @@ -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", @@ -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)...)