1
0
mirror of https://github.com/golang/go synced 2024-11-19 02:54:42 -07:00
go/ssa/interp/testdata/mrvchain.go
Robert Griesemer cc52b8b7f8 go.tools/go/types: clean up assignment checks (round 1)
Various bug fixes:
- don't allow := to redeclare non-variables
- don't permit a comma-ok expression as a two-value function return

Lots of dead code removed.

Fixes golang/go#5500.

R=adonovan
CC=golang-dev
https://golang.org/cl/10792044
2013-07-08 09:40:30 -07:00

67 lines
1.1 KiB
Go

// Tests of call chaining f(g()) when g has multiple return values (MRVs).
// See https://code.google.com/p/go/issues/detail?id=4573.
package main
func assert(actual, expected int) {
if actual != expected {
panic(actual)
}
}
func g() (int, int) {
return 5, 7
}
func g2() (float64, float64) {
return 5, 7
}
func f1v(x int, v ...int) {
assert(x, 5)
assert(v[0], 7)
}
func f2(x, y int) {
assert(x, 5)
assert(y, 7)
}
func f2v(x, y int, v ...int) {
assert(x, 5)
assert(y, 7)
assert(len(v), 0)
}
func complexArgs() (float64, float64) {
return 5, 7
}
func appendArgs() ([]string, string) {
return []string{"foo"}, "bar"
}
func h() (i interface{}, ok bool) {
m := map[int]string{1: "hi"}
i, ok = m[1] // string->interface{} conversion within multi-valued expression
return
}
func main() {
f1v(g())
f2(g())
f2v(g())
// TODO(gri): the typechecker still doesn't support these cases correctly.
// if c := complex(complexArgs()); c != 5+7i {
// panic(c)
// }
// if s := append(appendArgs()); len(s) != 2 || s[0] != "foo" || s[1] != "bar" {
// panic(s)
// }
i, ok := h()
if !ok || i.(string) != "hi" {
panic(i)
}
}