Fixed variable lifetime in loops
This commit is contained in:
@ -9,6 +9,10 @@ func Count(body AST, kind token.Kind, name string) int {
|
||||
for _, node := range body {
|
||||
switch node := node.(type) {
|
||||
case *Assign:
|
||||
if node.Name.Kind == kind && node.Name.Text() == name {
|
||||
count++
|
||||
}
|
||||
|
||||
count += node.Value.Count(kind, name)
|
||||
|
||||
case *Call:
|
||||
@ -18,7 +22,9 @@ func Count(body AST, kind token.Kind, name string) int {
|
||||
count += node.Value.Count(kind, name)
|
||||
|
||||
case *Return:
|
||||
count += node.Value.Count(kind, name)
|
||||
if node.Value != nil {
|
||||
count += node.Value.Count(kind, name)
|
||||
}
|
||||
|
||||
case *If:
|
||||
count += node.Condition.Count(kind, name)
|
||||
|
Reference in New Issue
Block a user