1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // initialization cycles
6
7 package init1
8
9 // issue 6683 (marked as WorkingAsIntended)
10
11 type T0 struct{}
12
13 func (T0) m() int { return y0 }
14
15 var x0 = T0{}
16
17 var y0 /* ERROR initialization cycle */ = x0.m()
18
19 type T1 struct{}
20
21 func (T1) m() int { return y1 }
22
23 var x1 interface {
24 m() int
25 } = T1{}
26
27 var y1 = x1.m() // no cycle reported, x1 is of interface type
28
29 // issue 6703 (modified)
30
31 var x2 /* ERROR initialization cycle */ = T2.m
32
33 var y2 = x2
34
35 type T2 struct{}
36
37 func (T2) m() int {
38 _ = y2
39 return 0
40 }
41
42 var x3 /* ERROR initialization cycle */ = T3.m(T3{}) // <<<< added (T3{})
43
44 var y3 = x3
45
46 type T3 struct{}
47
48 func (T3) m() int {
49 _ = y3
50 return 0
51 }
52
53 var x4 /* ERROR initialization cycle */ = T4{}.m // <<<< added {}
54
55 var y4 = x4
56
57 type T4 struct{}
58
59 func (T4) m() int {
60 _ = y4
61 return 0
62 }
63
64 var x5 /* ERROR initialization cycle */ = T5{}.m() // <<<< added ()
65
66 var y5 = x5
67
68 type T5 struct{}
69
70 func (T5) m() int {
71 _ = y5
72 return 0
73 }
74
75 // issue 4847
76 // simplified test case
77
78 var x6 = f6
79 var y6 /* ERROR initialization cycle */ = f6
80 func f6() { _ = y6 }
81
82 // full test case
83
84 type (
85 E int
86 S int
87 )
88
89 type matcher func(s *S) E
90
91 func matchList(s *S) E { return matcher(matchAnyFn)(s) }
92
93 var foo = matcher(matchList)
94
95 var matchAny /* ERROR initialization cycle */ = matcher(matchList)
96
97 func matchAnyFn(s *S) (err E) { return matchAny(s) }
View as plain text