Skip to content

Commit 1e27b76

Browse files
committed
[dev.go2go] go/types: report "inifinite expansion" cycles across instantiated types
Fixes #39938. Change-Id: I482b211189cefdc098df5acb4f858f6f1635ce60 Reviewed-on: https://go-review.googlesource.com/c/go/+/240519 Reviewed-by: Robert Griesemer <[email protected]>
1 parent 236ad5a commit 1e27b76

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

src/go/types/check_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ var tests = [][]string{
133133
{"fixedbugs/issue39754.go2"},
134134
{"fixedbugs/issue39755.go2"},
135135
{"fixedbugs/issue39768.go2"},
136+
{"fixedbugs/issue39938.go2"},
136137
}
137138

138139
var fset = token.NewFileSet()

src/go/types/decl.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,9 @@ func (check *Checker) validType(typ Type, path []Object) typeInfo {
349349
panic("internal error: cycle start not found")
350350
}
351351
return t.info
352+
353+
case *instance:
354+
return check.validType(t.expand(), path)
352355
}
353356

354357
return valid

src/go/types/fixedbugs/issue39938.go2

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
// Check "infinite expansion" cycle errors across instantiated types.
6+
7+
package p
8+
9+
type E0(type P) P
10+
type E1(type P) *P
11+
type E2(type P) struct{ P }
12+
type E3(type P) struct{ *P }
13+
14+
type T0 /* ERROR illegal cycle */ struct {
15+
_ E0(T0)
16+
}
17+
18+
type T0_ /* ERROR illegal cycle */ struct {
19+
(E0(T0_))
20+
}
21+
22+
type T1 struct {
23+
_ E1(T1)
24+
}
25+
26+
type T2 /* ERROR illegal cycle */ struct {
27+
_ E2(T2)
28+
}
29+
30+
type T3 struct {
31+
_ E3(T3)
32+
}
33+
34+
// some more complex cases
35+
36+
type T4 /* ERROR illegal cycle */ struct {
37+
_ E0(E2(T4))
38+
}
39+
40+
type T5 struct {
41+
_ E0(E2(E0(E1(E2([10]T5)))))
42+
}
43+
44+
type T6 /* ERROR illegal cycle */ struct {
45+
_ E0([10]E2(E0(E2(E2(T6)))))
46+
}
47+
48+
type T7 struct {
49+
_ E0([]E2(E0(E2(E2(T6)))))
50+
}

0 commit comments

Comments
 (0)