Skip to content

Commit

Permalink
cmd/compile: avoid compiler crash for recursive interface type
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
griesemer committed May 7, 2019
1 parent 49ad7bc commit dc0388c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 10 additions & 1 deletion src/cmd/compile/internal/gc/align.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions test/fixedbugs/issue23823.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
// compile
// errorcheck

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

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
}
*/

0 comments on commit dc0388c

Please sign in to comment.