compiler: allow to use multiple underscores in func arguments
It should still be present in the argument array in VM so just don't save them in the map. Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
fb31a81fd2
commit
8d562cef99
2 changed files with 18 additions and 0 deletions
|
@ -2,6 +2,7 @@ package compiler
|
|||
|
||||
import (
|
||||
"go/ast"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type varScope struct {
|
||||
|
@ -70,6 +71,12 @@ func (c *varScope) newVariable(t varType, name string) int {
|
|||
case varLocal:
|
||||
return c.newLocal(name)
|
||||
case varArgument:
|
||||
if name == "_" {
|
||||
// See #2204. This name won't actually be referenced.
|
||||
// This approach simplifies argument allocation and
|
||||
// makes debugging easier.
|
||||
name = "%_" + strconv.FormatUint(uint64(len(c.arguments)), 10)
|
||||
}
|
||||
_, ok := c.arguments[name]
|
||||
if ok {
|
||||
panic("argument is already allocated")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue