1
0
mirror of https://github.com/golang/go synced 2024-10-02 06:18:32 -06:00
go/ssa/interp/testdata/mrvchain.go
Rob Pike 01f8cd246d go.tools: add go/types, ssa, and cmd/vet
They will be deleted from their current homes once this has landed.
Changes made to import paths to make the code compile, and to find
errchk in the right place in cmd/vet's Makefile.
TODO in a later CL: tidy up vet.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/9495043
2013-05-17 13:20:39 -07:00

66 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() (interface{}, bool) {
m := map[int]string{1: "hi"}
return m[1] // string->interface{} conversion within multi-valued expression
}
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)
}
}