Commit c72092a2 authored by Hugo Moreau's avatar Hugo Moreau

global: fix when local and global has same id

In the second pass, local var with same name as global var was always
considerated as global. Not anymore.

 * transform/global2.go : Here.
parent ef7744c3
Pipeline #26345 failed with stage
in 1 minute and 49 seconds
......@@ -2,6 +2,7 @@ package transform
import (
"go/ast"
"go/token"
)
type Global2 struct {
......@@ -47,6 +48,15 @@ func (t *Global2) Pre(meta *Meta, v *Visitor) bool {
t.funcsVar[t.currentFunction.Name] = append(t.funcsVar[t.currentFunction.Name], node.Names[i].Name)
}
}
case *ast.AssignStmt:
if node.Tok == token.DEFINE {
for i := 0; i < len(node.Lhs); i++ {
switch lhs := node.Lhs[i].(type) {
case *ast.Ident:
t.funcsVar[t.currentFunction.Name] = append(t.funcsVar[t.currentFunction.Name], lhs.Name)
}
}
}
case *ast.Ident:
if find(t.globalVar, node.Name) && t.currentFunction != nil && t.currentFunction.Name != "main" && !find(t.funcsVar[t.currentFunction.Name], node.Name) {
ident := ast.NewIdent("G2P_" + node.Name + "_get_ptr")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment