diff options
author | Robert Griesemer <gri@golang.org> | 2021-07-02 18:12:02 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2021-07-07 23:42:29 +0000 |
commit | 18135150b0ce945735d242eb6259ffc9b5c767d0 (patch) | |
tree | 49e225267b7cb510e993142cfc650c7a87ad31e2 /src/cmd/compile/internal/types2/testdata | |
parent | d2bf94fb86b45609564919caa21c6b098b5197d3 (diff) | |
download | go-18135150b0ce945735d242eb6259ffc9b5c767d0.tar.gz go-18135150b0ce945735d242eb6259ffc9b5c767d0.zip |
[dev.typeparams] cmd/compile/internal/types2: don't permit method calls on ptr to type parameter receivers
Simplify the implementation of asInterface while at it.
For #47031.
Change-Id: Ie7d4fbbab898d961ed3c0b7772ba9604641be13f
Reviewed-on: https://go-review.googlesource.com/c/go/+/332609
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types2/testdata')
-rw-r--r-- | src/cmd/compile/internal/types2/testdata/check/issues.go2 | 10 | ||||
-rw-r--r-- | src/cmd/compile/internal/types2/testdata/fixedbugs/issue47031.go2 | 20 |
2 files changed, 24 insertions, 6 deletions
diff --git a/src/cmd/compile/internal/types2/testdata/check/issues.go2 b/src/cmd/compile/internal/types2/testdata/check/issues.go2 index 59dd4ae465..88ae294d7c 100644 --- a/src/cmd/compile/internal/types2/testdata/check/issues.go2 +++ b/src/cmd/compile/internal/types2/testdata/check/issues.go2 @@ -24,22 +24,20 @@ func _() { eql[io.Reader](nil, nil) } -// If we have a receiver of pointer type (below: *T) we must ignore -// the pointer in the implementation of the method lookup because -// the type bound of T is an interface and pointer to interface types -// have no methods and then the lookup would fail. +// If we have a receiver of pointer to type parameter type (below: *T) +// we don't have any methods, like for interfaces. type C[T any] interface { m() } // using type bound C func _[T C[T]](x *T) { - x.m() + x.m /* ERROR x\.m undefined */ () } // using an interface literal as bound func _[T interface{ m() }](x *T) { - x.m() + x.m /* ERROR x\.m undefined */ () } func f2[_ interface{ m1(); m2() }]() diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue47031.go2 b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue47031.go2 new file mode 100644 index 0000000000..b184f9b5b7 --- /dev/null +++ b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue47031.go2 @@ -0,0 +1,20 @@ +// Copyright 2021 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 + +type Mer interface { M() } + +func F[T Mer](p *T) { + p.M /* ERROR p\.M undefined */ () +} + +type MyMer int + +func (MyMer) M() {} + +func _() { + F(new(MyMer)) + F[Mer](nil) +} |