mirror of
https://github.com/traefik/yaegi.git
synced 2026-06-01 18:37:56 +00:00
* interp: fix handling of redeclaration in multi-assign expression In a statement like `a, b := f()` if `a` was previously declared, its symbol must be reused, a new symbol must not override its previous value. This is now fixed. * In case of redeclaration, reuse the existing only if the redeclared variable has the same type. Add _test/var16.go to check this use case. Fixes #1365.
20 lines
355 B
Go
20 lines
355 B
Go
package main
|
|
|
|
func getArray() ([]int, error) { println("getArray"); return []int{1, 2}, nil }
|
|
|
|
func getNum() (int, error) { println("getNum"); return 3, nil }
|
|
|
|
func main() {
|
|
if a, err := getNum(); err != nil {
|
|
println("#1", a)
|
|
} else if a, err := getArray(); err != nil {
|
|
println("#2", a)
|
|
}
|
|
println("#3")
|
|
}
|
|
|
|
// Output:
|
|
// getNum
|
|
// getArray
|
|
// #3
|