1// run
2
3// Copyright 2022 The Go Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
7package main
8
9var ok = false
10
11func f() func(int, int) int {
12	ok = true
13	return func(int, int) int { return 0 }
14}
15
16func g() (int, int) {
17	if !ok {
18		panic("FAIL")
19	}
20	return 0, 0
21}
22
23var _ = f()(g())
24
25func main() {
26	f1()
27	f2()
28	f3()
29	f4()
30}
31
32func f1() {
33	ok := false
34
35	f := func() func(int, int) {
36		ok = true
37		return func(int, int) {}
38	}
39	g := func() (int, int) {
40		if !ok {
41			panic("FAIL")
42		}
43		return 0, 0
44	}
45
46	f()(g())
47}
48
49type S struct{}
50
51func (S) f(int, int) {}
52
53func f2() {
54	ok := false
55
56	f := func() S {
57		ok = true
58		return S{}
59	}
60	g := func() (int, int) {
61		if !ok {
62			panic("FAIL")
63		}
64		return 0, 0
65	}
66
67	f().f(g())
68}
69
70func f3() {
71	ok := false
72
73	f := func() []func(int, int) {
74		ok = true
75		return []func(int, int){func(int, int) {}}
76	}
77	g := func() (int, int) {
78		if !ok {
79			panic("FAIL")
80		}
81		return 0, 0
82	}
83	f()[0](g())
84}
85
86type G[T any] struct{}
87
88func (G[T]) f(int, int) {}
89
90func f4() {
91	ok := false
92
93	f := func() G[int] {
94		ok = true
95		return G[int]{}
96	}
97	g := func() (int, int) {
98		if !ok {
99			panic("FAIL")
100		}
101		return 0, 0
102	}
103
104	f().f(g())
105}
106