File tree 6 files changed +19
-48
lines changed
src/cmd/compile/internal/gc 6 files changed +19
-48
lines changed Original file line number Diff line number Diff line change @@ -217,7 +217,7 @@ func dowidth(t *types.Type) {
217
217
}
218
218
219
219
// defer checkwidth calls until after we're done
220
- defercalc ++
220
+ defercheckwidth ()
221
221
222
222
lno := lineno
223
223
if asNode (t .Nod ) != nil {
@@ -391,11 +391,7 @@ func dowidth(t *types.Type) {
391
391
392
392
lineno = lno
393
393
394
- if defercalc == 1 {
395
- resumecheckwidth ()
396
- } else {
397
- defercalc --
398
- }
394
+ resumecheckwidth ()
399
395
}
400
396
401
397
// when a type's width should be known, we call checkwidth
@@ -440,24 +436,18 @@ func checkwidth(t *types.Type) {
440
436
}
441
437
442
438
func defercheckwidth () {
443
- // we get out of sync on syntax errors, so don't be pedantic.
444
- if defercalc != 0 && nerrors == 0 {
445
- Fatalf ("defercheckwidth" )
446
- }
447
- defercalc = 1
439
+ defercalc ++
448
440
}
449
441
450
442
func resumecheckwidth () {
451
- if defercalc == 0 {
452
- Fatalf ("resumecheckwidth" )
453
- }
454
-
455
- for len (deferredTypeStack ) > 0 {
456
- t := deferredTypeStack [len (deferredTypeStack )- 1 ]
457
- deferredTypeStack = deferredTypeStack [:len (deferredTypeStack )- 1 ]
458
- t .SetDeferwidth (false )
459
- dowidth (t )
443
+ if defercalc == 1 {
444
+ for len (deferredTypeStack ) > 0 {
445
+ t := deferredTypeStack [len (deferredTypeStack )- 1 ]
446
+ deferredTypeStack = deferredTypeStack [:len (deferredTypeStack )- 1 ]
447
+ t .SetDeferwidth (false )
448
+ dowidth (t )
449
+ }
460
450
}
461
451
462
- defercalc = 0
452
+ defercalc --
463
453
}
Original file line number Diff line number Diff line change @@ -298,21 +298,10 @@ func (r *importReader) doDecl(n *Node) {
298
298
299
299
// We also need to defer width calculations until
300
300
// after the underlying type has been assigned.
301
- //
302
- // TODO(mdempsky): Add nesting support directly to
303
- // {defer,resume}checkwidth? Width calculations are
304
- // already deferred during initial typechecking, but
305
- // not when we're expanding inline function bodies, so
306
- // we currently need to handle both cases here.
307
- deferring := defercalc != 0
308
- if ! deferring {
309
- defercheckwidth ()
310
- }
301
+ defercheckwidth ()
311
302
underlying := r .typ ()
312
303
copytype (typenod (t ), underlying )
313
- if ! deferring {
314
- resumecheckwidth ()
315
- }
304
+ resumecheckwidth ()
316
305
317
306
if underlying .IsInterface () {
318
307
break
Original file line number Diff line number Diff line change @@ -527,7 +527,6 @@ func Main(archInit func(*Arch)) {
527
527
// We also defer type alias declarations until phase 2
528
528
// to avoid cycles like #18640.
529
529
// TODO(gri) Remove this again once we have a fix for #25838.
530
- defercheckwidth ()
531
530
532
531
// Don't use range--typecheck can add closures to xtop.
533
532
timings .Start ("fe" , "typecheck" , "top1" )
@@ -549,7 +548,6 @@ func Main(archInit func(*Arch)) {
549
548
xtop [i ] = typecheck (n , ctxStmt )
550
549
}
551
550
}
552
- resumecheckwidth ()
553
551
554
552
// Phase 3: Type check function bodies.
555
553
// Don't use range--typecheck can add closures to xtop.
@@ -1035,7 +1033,6 @@ func loadsys() {
1035
1033
1036
1034
inimport = true
1037
1035
typecheckok = true
1038
- defercheckwidth ()
1039
1036
1040
1037
typs := runtimeTypes ()
1041
1038
for _ , d := range runtimeDecls {
@@ -1052,7 +1049,6 @@ func loadsys() {
1052
1049
}
1053
1050
1054
1051
typecheckok = false
1055
- resumecheckwidth ()
1056
1052
inimport = false
1057
1053
}
1058
1054
Original file line number Diff line number Diff line change @@ -3669,9 +3669,7 @@ func typecheckdef(n *Node) {
3669
3669
}
3670
3670
3671
3671
// regular type declaration
3672
- if Curfn != nil {
3673
- defercheckwidth ()
3674
- }
3672
+ defercheckwidth ()
3675
3673
n .SetWalkdef (1 )
3676
3674
setTypeNode (n , types .New (TFORW ))
3677
3675
n .Type .Sym = n .Sym
@@ -3682,9 +3680,7 @@ func typecheckdef(n *Node) {
3682
3680
// but it was reported. Silence future errors.
3683
3681
n .Type .SetBroke (true )
3684
3682
}
3685
- if Curfn != nil {
3686
- resumecheckwidth ()
3687
- }
3683
+ resumecheckwidth ()
3688
3684
}
3689
3685
3690
3686
ret:
Original file line number Diff line number Diff line change @@ -18,10 +18,10 @@ type I4 interface { // GC_ERROR "invalid recursive type"
18
18
I4 // GCCGO_ERROR "interface"
19
19
}
20
20
21
- type I5 interface {
21
+ type I5 interface { // GC_ERROR "invalid recursive type"
22
22
I6 // GCCGO_ERROR "interface"
23
23
}
24
24
25
- type I6 interface { // GC_ERROR "invalid recursive type"
25
+ type I6 interface {
26
26
I5 // GCCGO_ERROR "interface"
27
27
}
Original file line number Diff line number Diff line change 6
6
7
7
package p
8
8
9
- type I1 = interface { // ERROR "invalid recursive type"
9
+ type I1 = interface {
10
10
I2
11
11
}
12
12
13
- type I2 interface {
13
+ type I2 interface { // ERROR "invalid recursive type"
14
14
I1
15
15
}
You can’t perform that action at this time.
0 commit comments