Skip to content

Commit 6e86f51

Browse files
committed
[dev.go2go] go/types: don't rely on completed interfaces in isParameterized predicate
Also, take type lists into account when computing predicate. Addresses crash #27 of #39634. Updates #39634. Change-Id: Id6e1d0d86ac1cb9d79828a3b5fdfbeba0e6aace0 Reviewed-on: https://go-review.googlesource.com/c/go/+/240902 Reviewed-by: Robert Griesemer <[email protected]>
1 parent 167909e commit 6e86f51

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/go/types/fixedbugs/issue39634.go2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,7 @@ func F20(type t Z20)() { F20(t /* ERROR invalid composite literal type */ {}) }
4242
// crash 21
4343
type Z21 /* ERROR illegal cycle */ interface{ Z21 }
4444
func F21(type *T Z21)() { ( /* ERROR not used */ F21(Z21)) }
45+
46+
// crash 27
47+
func e27(type T)() interface{ (x27 /* ERROR not a type */ ) }
48+
func x27() { e27() /* ERROR cannot infer T */ }

src/go/types/infer.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,25 @@ func isParameterized(typ Type, seen map[Type]bool) (res bool) {
212212
return isParameterized(t.params, seen) || isParameterized(t.results, seen)
213213

214214
case *Interface:
215-
t.assertCompleteness()
216-
for _, m := range t.allMethods {
217-
if isParameterized(m.typ, seen) {
218-
return true
215+
if t.allMethods != nil {
216+
// interface is complete - quick test
217+
for _, m := range t.allMethods {
218+
if isParameterized(m.typ, seen) {
219+
return true
220+
}
219221
}
222+
return isParameterizedList(unpack(t.allTypes), seen)
220223
}
221224

225+
return t.iterate(func(t *Interface) bool {
226+
for _, m := range t.methods {
227+
if isParameterized(m.typ, seen) {
228+
return true
229+
}
230+
}
231+
return isParameterizedList(unpack(t.types), seen)
232+
}, nil)
233+
222234
case *Map:
223235
return isParameterized(t.key, seen) || isParameterized(t.elem, seen)
224236

0 commit comments

Comments
 (0)