]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: avoid compiler crash for recursive interface type
authorRobert Griesemer <gri@golang.org>
Mon, 6 May 2019 23:26:15 +0000 (16:26 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 7 May 2019 18:42:17 +0000 (18:42 +0000)
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>
src/cmd/compile/internal/gc/align.go
test/fixedbugs/issue23823.go

index 87a7de547a30ce05b1a3e21cadef431f304f87cb..17c549d2528d5e03ccd05876c165c7df33293938 100644 (file)
@@ -172,7 +172,16 @@ func dowidth(t *types.Type) {
        if t.Width == -2 {
                if !t.Broke() {
                        t.SetBroke(true)
-                       yyerrorl(asNode(t.Nod).Pos, "invalid recursive type %v", t)
+                       // t.Nod should not be nil here, but in some cases is appears to be
+                       // (see issue #23823). For now (temporary work-around) at a minimum
+                       // don't crash and provide a meaningful error message.
+                       // TODO(gri) determine the correct fix during a regular devel cycle
+                       // (see issue #31872).
+                       if t.Nod == nil {
+                               yyerror("invalid recursive type %v", t)
+                       } else {
+                               yyerrorl(asNode(t.Nod).Pos, "invalid recursive type %v", t)
+                       }
                }
 
                t.Width = 0
index 9297966cbd6f67a233bf0c4e207e03d6447ef24a..2f802d09886064a7a3c75e1e4546b5862b0a0e73 100644 (file)
@@ -1,4 +1,4 @@
-// compile
+// errorcheck
 
 // Copyright 2018 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
@@ -6,14 +6,10 @@
 
 package p
 
-// The compiler cannot handle this. Disabled for now.
-// See issue #25838.
-/*
 type I1 = interface {
        I2
 }
 
-type I2 interface {
+type I2 interface { // ERROR "invalid recursive type"
        I1
 }
-*/