GoPLS Viewer

Home|gopls/go/ssa/interp/testdata/mrvchain.go
1// Tests of call chaining f(g()) when g has multiple return values (MRVs).
2// See https://code.google.com/p/go/issues/detail?id=4573.
3
4package main
5
6func assert(actualexpected int) {
7    if actual != expected {
8        panic(actual)
9    }
10}
11
12func g() (intint) {
13    return 57
14}
15
16func g2() (float64float64) {
17    return 57
18}
19
20func f1v(x intv ...int) {
21    assert(x5)
22    assert(v[0], 7)
23}
24
25func f2(xy int) {
26    assert(x5)
27    assert(y7)
28}
29
30func f2v(xy intv ...int) {
31    assert(x5)
32    assert(y7)
33    assert(len(v), 0)
34}
35
36func complexArgs() (float64float64) {
37    return 57
38}
39
40func appendArgs() ([]stringstring) {
41    return []string{"foo"}, "bar"
42}
43
44func h() (i interface{}, ok bool) {
45    m := map[int]string{1"hi"}
46    iok = m[1// string->interface{} conversion within multi-valued expression
47    return
48}
49
50func h2() (i interface{}, ok bool) {
51    ch := make(chan string1)
52    ch <- "hi"
53    iok = <-ch // string->interface{} conversion within multi-valued expression
54    return
55}
56
57func main() {
58    f1v(g())
59    f2(g())
60    f2v(g())
61    if c := complex(complexArgs()); c != 5+7i {
62        panic(c)
63    }
64    if s := append(appendArgs()); len(s) != 2 || s[0] != "foo" || s[1] != "bar" {
65        panic(s)
66    }
67    iok := h()
68    if !ok || i.(string) != "hi" {
69        panic(i)
70    }
71    iok = h2()
72    if !ok || i.(string) != "hi" {
73        panic(i)
74    }
75}
76
MembersX
g
g2
f2.y
h.i
h.m
assert.expected
complexArgs
h2
h2.i
f2v.v
f1v
f1v.x
f1v.v
f2.x
f2v
f2v.x
f2v.y
assert.actual
h2.ok
h2.ch
appendArgs
h.ok
Members
X