Fixed variable lifetime in loops

This commit is contained in:
Eduard Urbach 2024-07-16 20:22:28 +02:00
parent 43a6e85929
commit c2b42fe2ea
Signed by: eduard
GPG key ID: 49226B848C78F6C8
11 changed files with 90 additions and 18 deletions

View file

@ -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)