compiler: do not allocate slotes for unused "_" vars

This commit is contained in:
Evgenii Stratonikov 2020-09-06 15:26:03 +03:00
parent 0b44a43043
commit 18369c489e
3 changed files with 29 additions and 7 deletions

View file

@ -434,13 +434,15 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
switch t := spec.(type) {
case *ast.ValueSpec:
for _, id := range t.Names {
if c.scope == nil {
// it is a global declaration
c.newGlobal("", id.Name)
} else {
c.scope.newLocal(id.Name)
if id.Name != "_" {
if c.scope == nil {
// it is a global declaration
c.newGlobal("", id.Name)
} else {
c.scope.newLocal(id.Name)
}
c.registerDebugVariable(id.Name, t.Type)
}
c.registerDebugVariable(id.Name, t.Type)
}
for i := range t.Names {
if len(t.Values) != 0 {