Debian Codegraph @

go/analysis/passes/stdversion/testdata/test.txtar

raw
1 Test of "too new" diagnostics from the stdversion analyzer.
2
3 This test references go1.21 and go1.22 symbols from std.
4
5 See also gopls/internal/test/marker/testdata/diagnostics/stdversion.txt
6 which runs the same test within the gopls analysis driver, to ensure
7 coverage of per-file Go version support.
8
9 -- go.work --
10 go 1.22
11
12 use .
13 use mod20
14 use mod21
15 use mod22
16 use old
17
18 -- go.mod --
19 module example.com
20
21 go 1.21
22
23 -- basic/basic.go --
24 // File version is 1.21.
25 package basic
26
27 import "go/types"
28
29 func _() {
30 // old package-level type
31 var _ types.Info // ok: defined by go1.0
32
33 // new field of older type
34 _ = new(types.Info).FileVersions // want `types.FileVersions requires go1.22 or later \(module is go1.21\)`
35
36 // new method of older type
37 new(types.Info).PkgNameOf // want `types.PkgNameOf requires go1.22 or later \(module is go1.21\)`
38
39 // new package-level type
40 var a types.Alias // want `types.Alias requires go1.22 or later \(module is go1.21\)`
41
42 // new method of new type
43 a.Underlying() // no diagnostic
44 }
45
46 -- despite/errors.go --
47 // File version is 1.21.
48
49 // Check that RunDespiteErrors is enabled.
50 package ignore
51
52 import "go/types"
53
54 func _() {
55 // report something before the syntax error.
56 _ = new(types.Info).FileVersions // want `types.FileVersions requires go1.22 or later \(module is go1.21\)`
57 }
58
59 invalid syntax // exercise RunDespiteErrors
60
61 -- mod20/go.mod --
62 module example.com/mod20
63
64 go 1.20
65
66 -- mod20/notag.go --
67 // The 1.20 module is before the forward compatibility regime:
68 // The file's build tag effects selection, but
69 // not language semantics, so stdversion is silent.
70
71 package mod20
72
73 import "go/types"
74
75 func _() {
76 var _ types.Alias
77 }
78
79 -- mod20/tag16.go --
80 // The 1.20 module is before the forward compatibility regime:
81 // The file's build tag effects selection, but
82 // not language semantics, so stdversion is silent.
83
84 //go:build go1.16
85
86 package mod20
87
88 import "bytes"
89 import "go/types"
90
91 var _ = bytes.Clone
92 var _ = types.Alias
93
94 -- mod20/tag22.go --
95 // The 1.20 module is before the forward compatibility regime:
96 // The file's build tag effects selection, but
97 // not language semantics, so stdversion is silent.
98
99 //go:build go1.22
100
101 package mod20
102
103 import "bytes"
104 import "go/types"
105
106 var _ = bytes.Clone
107 var _ = types.Alias
108
109 -- mod21/go.mod --
110 module example.com/mod21
111
112 go 1.21
113
114 -- mod21/notag.go --
115 // File version is 1.21.
116 package mod21
117
118 import "go/types"
119
120 func _() {
121 // old package-level type
122 var _ types.Info // ok: defined by go1.0
123
124 // new field of older type
125 _ = new(types.Info).FileVersions // want `types.FileVersions requires go1.22 or later \(module is go1.21\)`
126
127 // new method of older type
128 new(types.Info).PkgNameOf // want `types.PkgNameOf requires go1.22 or later \(module is go1.21\)`
129
130 // new package-level type
131 var a types.Alias // want `types.Alias requires go1.22 or later \(module is go1.21\)`
132
133 // new method of new type
134 a.Underlying() // no diagnostic
135 }
136
137 -- mod21/tag16.go --
138 // File version is 1.21.
139 //
140 // The module is within the forward compatibility regime so
141 // the build tag (1.16) can modify the file version, but it cannot
142 // go below the 1.21 "event horizon" (#68658).
143
144 //go:build go1.16
145
146 package mod21
147
148 import "bytes"
149 import "go/types"
150
151 var _ = bytes.Clone
152 var _ = types.Alias // want `types.Alias requires go1.22 or later \(module is go1.21\)`
153
154 -- mod21/tag22.go --
155 // File version is 1.22.
156 //
157 // The module is within the forward compatibility regime so
158 // the build tag (1.22) updates the file version to 1.22.
159
160 //go:build go1.22
161
162 package mod21
163
164 import "bytes"
165 import "go/types"
166
167 var _ = bytes.Clone
168 var _ = types.Alias
169
170 -- mod22/go.mod --
171 module example.com/mod22
172
173 go 1.22
174
175 -- mod22/notag.go --
176 // File version is 1.22.
177 package mod22
178
179 import "go/types"
180
181 func _() {
182 var _ = bytes.Clone
183 var _ = types.Alias
184 }
185
186 -- mod22/tag16.go --
187 // File version is 1.21.
188 //
189 // The module is within the forward compatibility regime so
190 // the build tag (1.16) can modify the file version, but it cannot
191 // go below the 1.21 "event horizon" (#68658).
192
193 //go:build go1.16
194
195 package mod22
196
197 import "bytes"
198 import "go/types"
199
200 var _ = bytes.Clone
201 var _ = types.Alias // want `types.Alias requires go1.22 or later \(file is go1.21\)`
202
203 -- old/go.mod --
204 module example.com/old
205
206 go 1.5
207
208 -- old/notag.go --
209 package old
210
211 import "go/types"
212
213 var _ types.Alias // no diagnostic: go.mod is too old for us to care
214
215 -- old/tag21.go --
216 // The build tag is ignored due to the module version.
217
218 //go:build go1.21
219
220 package old
221
222 import "go/types"
223
224 var _ = types.Alias // no diagnostic: go.mod is too old for us to care