File tree 5 files changed +79
-2
lines changed
cmd/compile/internal/types2 5 files changed +79
-2
lines changed Original file line number Diff line number Diff line change @@ -735,7 +735,7 @@ func (check *Checker) declStmt(list []syntax.Decl) {
735
735
top := len (check .delayed )
736
736
737
737
// iota is the index of the current constDecl within the group
738
- if first < 0 || list [index - 1 ].(* syntax.ConstDecl ).Group != s .Group {
738
+ if first < 0 || s . Group == nil || list [index - 1 ].(* syntax.ConstDecl ).Group != s .Group {
739
739
first = index
740
740
last = nil
741
741
}
Original file line number Diff line number Diff line change @@ -339,7 +339,7 @@ func (check *Checker) collectObjects() {
339
339
340
340
case * syntax.ConstDecl :
341
341
// iota is the index of the current constDecl within the group
342
- if first < 0 || file .DeclList [index - 1 ].(* syntax.ConstDecl ).Group != s .Group {
342
+ if first < 0 || s . Group == nil || file .DeclList [index - 1 ].(* syntax.ConstDecl ).Group != s .Group {
343
343
first = index
344
344
last = nil
345
345
}
Original file line number Diff line number Diff line change @@ -349,6 +349,25 @@ const _ = unsafe.Sizeof(func() {
349
349
assert(iota == 0)
350
350
})
351
351
352
+ // issue #52438
353
+ const i1 = iota
354
+ const i2 = iota
355
+ const i3 = iota
356
+
357
+ func _() {
358
+ assert(i1 == 0)
359
+ assert(i2 == 0)
360
+ assert(i3 == 0)
361
+
362
+ const i4 = iota
363
+ const i5 = iota
364
+ const i6 = iota
365
+
366
+ assert(i4 == 0)
367
+ assert(i5 == 0)
368
+ assert(i6 == 0)
369
+ }
370
+
352
371
// untyped constants must not get arbitrarily large
353
372
const prec = 512 // internal maximum precision for integers
354
373
const maxInt = (1<<(prec/2) - 1) * (1<<(prec/2) + 1) // == 1<<prec - 1
Original file line number Diff line number Diff line change @@ -349,6 +349,25 @@ const _ = unsafe.Sizeof(func() {
349
349
assert(iota == 0)
350
350
})
351
351
352
+ // issue #52438
353
+ const i1 = iota
354
+ const i2 = iota
355
+ const i3 = iota
356
+
357
+ func _() {
358
+ assert(i1 == 0)
359
+ assert(i2 == 0)
360
+ assert(i3 == 0)
361
+
362
+ const i4 = iota
363
+ const i5 = iota
364
+ const i6 = iota
365
+
366
+ assert(i4 == 0)
367
+ assert(i5 == 0)
368
+ assert(i6 == 0)
369
+ }
370
+
352
371
// untyped constants must not get arbitrarily large
353
372
const prec = 512 // internal maximum precision for integers
354
373
const maxInt = (1<<(prec/2) - 1) * (1<<(prec/2) + 1) // == 1<<prec - 1
Original file line number Diff line number Diff line change
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
+
7
+ package main
8
+
9
+ const c1 = iota
10
+ const c2 = iota
11
+
12
+ const c3 = 0 + iota << 8
13
+ const c4 = 1 + iota << 8
14
+
15
+ func main () {
16
+ if c1 != 0 {
17
+ panic (c1 )
18
+ }
19
+ if c2 != 0 {
20
+ panic (c2 )
21
+ }
22
+
23
+ if c3 != 0 {
24
+ panic (c3 )
25
+ }
26
+ if c4 != 1 {
27
+ panic (c4 )
28
+ }
29
+
30
+ const c5 = iota
31
+ const c6 = iota
32
+
33
+ if c5 != 0 {
34
+ panic (c5 )
35
+ }
36
+ if c6 != 0 {
37
+ panic (c6 )
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments