Skip to content

Commit dc0388c

Browse files
committed
cmd/compile: avoid compiler crash for recursive interface type
This change is a simple work-around to avoid a compiler crash and provide a reasonable error message. A future change should fix the root cause for this problem. Fixes #23823. Change-Id: Ifc80d9f4d35e063c378e54d5cd8d1cf4c0d2ec6a Reviewed-on: https://go-review.googlesource.com/c/go/+/175518 Reviewed-by: Ian Lance Taylor <iant@golang.org>
1 parent 49ad7bc commit dc0388c

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/cmd/compile/internal/gc/align.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,16 @@ func dowidth(t *types.Type) {
172172
if t.Width == -2 {
173173
if !t.Broke() {
174174
t.SetBroke(true)
175-
yyerrorl(asNode(t.Nod).Pos, "invalid recursive type %v", t)
175+
// t.Nod should not be nil here, but in some cases is appears to be
176+
// (see issue #23823). For now (temporary work-around) at a minimum
177+
// don't crash and provide a meaningful error message.
178+
// TODO(gri) determine the correct fix during a regular devel cycle
179+
// (see issue #31872).
180+
if t.Nod == nil {
181+
yyerror("invalid recursive type %v", t)
182+
} else {
183+
yyerrorl(asNode(t.Nod).Pos, "invalid recursive type %v", t)
184+
}
176185
}
177186

178187
t.Width = 0

test/fixedbugs/issue23823.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
// compile
1+
// errorcheck
22

33
// Copyright 2018 The Go Authors. All rights reserved.
44
// Use of this source code is governed by a BSD-style
55
// license that can be found in the LICENSE file.
66

77
package p
88

9-
// The compiler cannot handle this. Disabled for now.
10-
// See issue #25838.
11-
/*
129
type I1 = interface {
1310
I2
1411
}
1512

16-
type I2 interface {
13+
type I2 interface { // ERROR "invalid recursive type"
1714
I1
1815
}
19-
*/

0 commit comments

Comments
 (0)