Skip to content

Commit 167909e

Browse files
committed
[dev.go2go] go/types: don't modify Named.underlying when checking validity
Addresses crash #20 of #39634. Added test, also for some of the other cases that don't crash anymore. Updates #39634. Change-Id: I999e376985a443ac435f64a7c249f891e7b7a6d7 Reviewed-on: https://go-review.googlesource.com/c/go/+/240901 Reviewed-by: Robert Griesemer <[email protected]>
1 parent 4dde96e commit 167909e

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

src/go/types/check_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ var tests = [][]string{
125125
// Go 2 prototype bug fixes
126126
// TODO(gri) Eliminate the need to enumerate these tests here.
127127
// Should just traverse that directory.
128+
{"fixedbugs/issue39634.go2"},
128129
{"fixedbugs/issue39664.go2"},
129130
{"fixedbugs/issue39680.go2"},
130131
{"fixedbugs/issue39693.go2"},

src/go/types/decl.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@ func (check *Checker) validType(typ Type, path []Object) typeInfo {
342342
if tn == t.obj {
343343
check.cycleError(path[i:])
344344
t.info = invalid
345-
t.underlying = Typ[Invalid]
346345
return t.info
347346
}
348347
}

src/go/types/fixedbugs/issue39634.go2

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2020 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package p
6+
7+
// crash 1
8+
type nt(type )interface{g /* ERROR undeclared name */ }
9+
type ph(type e nt,g(d /* ERROR undeclared name */ ))s /* ERROR undeclared name */
10+
func(*ph(e,e /* ERROR redeclared */ ))h(d /* ERROR undeclared name */ )
11+
12+
// crash 2
13+
type Numeric2 interface{t /* ERROR not a type */ }
14+
func t(type T Numeric2)(s[]T){0 /* ERROR not a type */ (){s /* ERROR cannot index */ [0][0]}}
15+
16+
// crash 4
17+
type Numeric4 interface{t4 /* ERROR not a type */ }
18+
func t4(type T Numeric4)(s[]T){if( /* ERROR non-boolean */ 0){*s /* ERROR cannot indirect */ [0]}}
19+
20+
// crash 7
21+
type foo7 interface { bar() }
22+
type x7(type A) struct{ foo7 }
23+
func main7() { var _ foo7 = x7(int){} }
24+
25+
// crash 8
26+
type foo8(type A) interface { type A }
27+
func bar8(type A foo8(A))(a A) {}
28+
func main8() {}
29+
30+
// crash 17
31+
type Y17 interface{ c() }
32+
type Z17 interface {
33+
c() Y17
34+
Y17 /* ERROR duplicate method */
35+
}
36+
func F17(type T Z17)(T)
37+
38+
// crash 20
39+
type Z20 /* ERROR illegal cycle */ interface{ Z20 }
40+
func F20(type t Z20)() { F20(t /* ERROR invalid composite literal type */ {}) }
41+
42+
// crash 21
43+
type Z21 /* ERROR illegal cycle */ interface{ Z21 }
44+
func F21(type *T Z21)() { ( /* ERROR not used */ F21(Z21)) }

0 commit comments

Comments
 (0)