Skip to content

Commit f0e6640

Browse files
committed
[dev.go2go] go/types: generic types in selector expressions must be instantiated
Addresses crash 24 of #39634. Updates #39634. Change-Id: If44e834834a07719e7f727d12cc24ac4af0997e6 Reviewed-on: https://go-review.googlesource.com/c/go/+/245739 Reviewed-by: Robert Griesemer <[email protected]>
1 parent 0db4da5 commit f0e6640

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/go/types/call.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,11 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr) {
521521
goto Error
522522
}
523523

524+
if x.mode == typexpr && isGeneric(x.typ) {
525+
check.errorf(e.Pos(), "cannot use generic type %s without instantiation", x.typ)
526+
goto Error
527+
}
528+
524529
obj, index, indirect = check.lookupFieldOrMethod(x.typ, x.mode == variable, check.pkg, sel)
525530
if obj == nil {
526531
switch {

src/go/types/fixedbugs/issue39634.go2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ func F20(type t Z20)() { F20(t /* ERROR invalid composite literal type */ {}) }
6464
type Z21 /* ERROR illegal cycle */ interface{ Z21 }
6565
func F21(type *T Z21)() { ( /* ERROR not used */ F21(Z21)) }
6666

67+
// crash 24
68+
type T24(type P) P
69+
func (r T24(P)) m() { T24 /* ERROR without instantiation */ .m() }
70+
6771
// crash 27
6872
func e27(type T)() interface{ (x27 /* ERROR not a type */ ) }
6973
func x27() { e27() /* ERROR cannot infer T */ }

0 commit comments

Comments
 (0)