Skip to content

Commit

Permalink
fix: lookup index operand variables
Browse files Browse the repository at this point in the history
  • Loading branch information
didroe committed Mar 21, 2024
1 parent 14db980 commit 61020b5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions internal/languages/golang/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (analyzer *analyzer) Analyze(node *sitter.Node, visitChildren func() error)
case "identifier":
return visitChildren()
case "index_expression":
return visitChildren()
return analyzer.analyzeIndexExpression(node, visitChildren)
default:
analyzer.builder.Dataflow(node, analyzer.builder.ChildrenFor(node)...)
return visitChildren()
Expand Down Expand Up @@ -191,6 +191,13 @@ func (analyzer *analyzer) analyzeSelectorExpression(node *sitter.Node, visitChil
return visitChildren()
}

// foo[bar]
func (analyzer *analyzer) analyzeIndexExpression(node *sitter.Node, visitChildren func() error) error {
analyzer.lookupVariable(node.ChildByFieldName("operand"))

return visitChildren()
}

// method parameter declaration
//
// fn(a string)
Expand Down Expand Up @@ -244,6 +251,5 @@ func (analyzer *analyzer) lookupVariable(node *sitter.Node) {

if pointsToNode := analyzer.scope.Lookup(analyzer.builder.ContentFor(node)); pointsToNode != nil {
analyzer.builder.Alias(node, pointsToNode)
} else {
}
}

0 comments on commit 61020b5

Please sign in to comment.