compiler: Initialize named returns to default values

Make them behave as locals. We must initialize them at the start
because the default value could also be used inside the function body.

Signed-off-by: Evgenii Stratonikov <fyfyrchik@runbox.com>
This commit is contained in:
Evgenii Stratonikov 2024-04-04 17:51:03 +03:00
parent f2bb4d455b
commit 78cefca5c9
2 changed files with 31 additions and 1 deletions

View file

@ -120,6 +120,19 @@ func TestNamedReturn(t *testing.T) {
t.Run("AnotherVariable", runCase("b, c", big.NewInt(5)))
}
func TestNamedReturnDefault(t *testing.T) {
src := `package foo
func Main() int {
a, b, c := f()
return a + b + c
}
func f() (_ int, b int, c int) {
b += 1
return
}`
eval(t, src, big.NewInt(1))
}
func TestTypeAssertReturn(t *testing.T) {
src := `
package main