Merge pull request #631 from nspcc-dev/fix/return3

compiler: fix a bug with assignment to underscore
This commit is contained in:
Roman Khimov 2020-01-29 18:32:43 +03:00 committed by GitHub
commit 0ccc59628c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View file

@ -253,8 +253,12 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
ast.Walk(c, n.Rhs[i])
}
l := c.scope.loadLocal(t.Name)
c.emitStoreLocal(l)
if t.Name == "_" {
emitOpcode(c.prog.BinWriter, opcode.DROP)
} else {
l := c.scope.loadLocal(t.Name)
c.emitStoreLocal(l)
}
}
case *ast.SelectorExpr:

View file

@ -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