Merge pull request #2644 from nspcc-dev/fix-gen-decl
compiler: allow multi-return variables declaration
This commit is contained in:
commit
06f50630ac
2 changed files with 38 additions and 2 deletions
|
@ -582,6 +582,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
|||
for _, spec := range n.Specs {
|
||||
switch t := spec.(type) {
|
||||
case *ast.ValueSpec:
|
||||
multiRet := n.Tok == token.VAR && len(t.Values) != 0 && len(t.Names) != len(t.Values)
|
||||
for _, id := range t.Names {
|
||||
if id.Name != "_" {
|
||||
if c.scope == nil {
|
||||
|
@ -590,12 +591,16 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
|||
} else {
|
||||
c.scope.newLocal(id.Name)
|
||||
}
|
||||
c.registerDebugVariable(id.Name, t.Type)
|
||||
if !multiRet {
|
||||
c.registerDebugVariable(id.Name, t.Type)
|
||||
}
|
||||
}
|
||||
}
|
||||
for i := range t.Names {
|
||||
if len(t.Values) != 0 {
|
||||
ast.Walk(c, t.Values[i])
|
||||
if i == 0 || !multiRet {
|
||||
ast.Walk(c, t.Values[i])
|
||||
}
|
||||
} else {
|
||||
c.emitDefault(c.typeOf(t.Type))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue