@@ -2,27 +2,27 @@ Test of "too new" diagnostics from the stdversion analyzer.
2
2
3
3
This test references go1.21 and go1.22 symbols from std.
4
4
5
- It uses a txtar file due to golang/go#37054.
6
-
7
5
See also gopls/internal/test/marker/testdata/diagnostics/stdversion.txt
8
6
which runs the same test within the gopls analysis driver, to ensure
9
7
coverage of per-file Go version support.
10
8
11
9
-- go.work --
12
- go 1.21
10
+ go 1.22
13
11
14
12
use .
15
- use sub
16
- use sub20
13
+ use mod20
14
+ use mod21
15
+ use mod22
17
16
use old
18
17
19
18
-- go.mod --
20
19
module example.com
21
20
22
21
go 1.21
23
22
24
- -- a/a.go --
25
- package a
23
+ -- basic/basic.go --
24
+ // File version is 1.21.
25
+ package basic
26
26
27
27
import "go/types"
28
28
@@ -43,13 +43,77 @@ func _() {
43
43
a.Underlying() // no diagnostic
44
44
}
45
45
46
- -- sub/go.mod --
47
- module example.com/sub
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
48
111
49
112
go 1.21
50
113
51
- -- sub/sub.go --
52
- package sub
114
+ -- mod21/notag.go --
115
+ // File version is 1.21.
116
+ package mod21
53
117
54
118
import "go/types"
55
119
@@ -70,79 +134,91 @@ func _() {
70
134
a.Underlying() // no diagnostic
71
135
}
72
136
73
- invalid syntax // exercise RunDespiteErrors
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).
74
143
75
- -- sub/tagged.go --
76
- //go:build go1.22
144
+ //go:build go1.16
77
145
78
- package sub
146
+ package mod21
79
147
148
+ import "bytes"
80
149
import "go/types"
81
150
82
- func _() {
83
- // old package-level type
84
- var _ types.Info
151
+ var _ = bytes.Clone
152
+ var _ = types.Alias // want `types.Alias requires go1.22 or later \(module is go1.21\)`
85
153
86
- // new field of older type
87
- _ = new(types.Info).FileVersions
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.
88
159
89
- // new method of older type
90
- new(types.Info).PkgNameOf
160
+ //go:build go1.22
91
161
92
- // new package-level type
93
- var a types.Alias
162
+ package mod21
94
163
95
- // new method of new type
96
- a.Underlying()
97
- }
164
+ import "bytes"
165
+ import "go/types"
98
166
99
- -- old/go.mod --
100
- module example.com/old
167
+ var _ = bytes.Clone
168
+ var _ = types.Alias
101
169
102
- go 1.5
170
+ -- mod22/go.mod --
171
+ module example.com/mod22
103
172
104
- -- old/old.go --
105
- package old
173
+ go 1.22
174
+
175
+ -- mod22/notag.go --
176
+ // File version is 1.22.
177
+ package mod22
106
178
107
179
import "go/types"
108
180
109
- var _ types.Alias // no diagnostic: go.mod is too old for us to care
181
+ func _() {
182
+ var _ = bytes.Clone
183
+ var _ = types.Alias
184
+ }
110
185
111
- -- sub/oldtagged .go --
112
- // The file Go version (1.16) overrides the go.mod Go version ( 1.21),
113
- // even when this means a downgrade (#67123).
114
- // (stdversion is silent for go.mod versions before 1.21:
115
- // before the forward compatibility regime, the meaning
116
- // of the go.mod version was not clearly defined.)
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).
117
192
118
193
//go:build go1.16
119
194
120
- package sub
195
+ package mod22
121
196
122
197
import "bytes"
123
198
import "go/types"
124
199
125
- var _ = bytes.Clone // want `bytes.Clone requires go1.20 or later \(file is go1.16\)`
126
- var _ = types.Alias // want `types.Alias requires go1.22 or later \(file is go1.16 \)`
200
+ var _ = bytes.Clone
201
+ var _ = types.Alias // want `types.Alias requires go1.22 or later \(file is go1.21 \)`
127
202
128
- -- sub20 /go.mod --
129
- module example.com/sub20
203
+ -- old /go.mod --
204
+ module example.com/old
130
205
131
- go 1.20
206
+ go 1.5
132
207
133
- -- sub20/oldtagged.go --
134
- // Same test again, but with a go1.20 mod,
135
- // before the forward compatibility regime:
136
- // The file's build tag effects selection, but
137
- // not language semantics, so stdversion is silent.
208
+ -- old/notag.go --
209
+ package old
138
210
139
- //go:build go1.16
211
+ import "go/types"
140
212
141
- package sub
213
+ var _ types.Alias // no diagnostic: go.mod is too old for us to care
142
214
143
- import "bytes"
144
- import "go/types"
215
+ -- old/tag21.go --
216
+ // The build tag is ignored due to the module version.
145
217
146
- var _ = bytes.Clone
147
- var _ = types.Alias
218
+ //go:build go1.21
219
+
220
+ package old
221
+
222
+ import "go/types"
148
223
224
+ var _ = types.Alias // no diagnostic: go.mod is too old for us to care
0 commit comments