compiler: fix a bug with assignment to underscore
When using underscore it does not appear in the list of local variables, so it can't be assigned. In this commit the value is dropped.
This commit is contained in:
parent
d234a1e718
commit
8b922c057c
2 changed files with 21 additions and 2 deletions
|
@ -253,9 +253,13 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
|||
ast.Walk(c, n.Rhs[i])
|
||||
}
|
||||
|
||||
if t.Name == "_" {
|
||||
emitOpcode(c.prog.BinWriter, opcode.DROP)
|
||||
} else {
|
||||
l := c.scope.loadLocal(t.Name)
|
||||
c.emitStoreLocal(l)
|
||||
}
|
||||
}
|
||||
|
||||
case *ast.SelectorExpr:
|
||||
switch expr := t.X.(type) {
|
||||
|
|
|
@ -37,6 +37,21 @@ func TestMultipleReturn2(t *testing.T) {
|
|||
eval(t, src, big.NewInt(9))
|
||||
}
|
||||
|
||||
func TestMultipleReturnUnderscore(t *testing.T) {
|
||||
src := `
|
||||
package hello
|
||||
func f3() (int, int, int) {
|
||||
return 5, 6, 7
|
||||
}
|
||||
|
||||
func Main() int {
|
||||
a, _, c := f3()
|
||||
return a+c
|
||||
}
|
||||
`
|
||||
eval(t, src, big.NewInt(12))
|
||||
}
|
||||
|
||||
func TestMultipleReturnWithArg(t *testing.T) {
|
||||
src := `
|
||||
package hello
|
||||
|
|
Loading…
Reference in a new issue