Fixed variable lifetime in loops
This commit is contained in:
parent
43a6e85929
commit
c2b42fe2ea
11 changed files with 90 additions and 18 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue