mirror of
https://github.com/golang/go
synced 2024-09-05 07:54:46 +00:00
[dev.typeparams] go/types: fix generic type indirection
This is a port of CL 333890 to go/types. Change-Id: I8ee20f405dad98083bb5e91636044d132a95d909 Reviewed-on: https://go-review.googlesource.com/c/go/+/335081 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
62f6f130fe
commit
82f875d735
|
@ -1400,13 +1400,24 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
|
||||||
case typexpr:
|
case typexpr:
|
||||||
x.typ = &Pointer{base: x.typ}
|
x.typ = &Pointer{base: x.typ}
|
||||||
default:
|
default:
|
||||||
if typ := asPointer(x.typ); typ != nil {
|
var base Type
|
||||||
x.mode = variable
|
if !underIs(x.typ, func(u Type) bool {
|
||||||
x.typ = typ.base
|
p, _ := u.(*Pointer)
|
||||||
} else {
|
if p == nil {
|
||||||
check.invalidOp(x, _InvalidIndirection, "cannot indirect %s", x)
|
check.invalidOp(x, _InvalidIndirection, "cannot indirect %s", x)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if base != nil && !Identical(p.base, base) {
|
||||||
|
check.invalidOp(x, _Todo, "pointers of %s must have identical base types", x)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
base = p.base
|
||||||
|
return true
|
||||||
|
}) {
|
||||||
goto Error
|
goto Error
|
||||||
}
|
}
|
||||||
|
x.mode = variable
|
||||||
|
x.typ = base
|
||||||
}
|
}
|
||||||
|
|
||||||
case *ast.UnaryExpr:
|
case *ast.UnaryExpr:
|
||||||
|
|
29
src/go/types/testdata/examples/operations.go2
vendored
Normal file
29
src/go/types/testdata/examples/operations.go2
vendored
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
// 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
|
||||||
|
|
||||||
|
// indirection
|
||||||
|
|
||||||
|
func _[P any](p P) {
|
||||||
|
_ = *p // ERROR cannot indirect p
|
||||||
|
}
|
||||||
|
|
||||||
|
func _[P interface{ int }](p P) {
|
||||||
|
_ = *p // ERROR cannot indirect p
|
||||||
|
}
|
||||||
|
|
||||||
|
func _[P interface{ *int }](p P) {
|
||||||
|
_ = *p
|
||||||
|
}
|
||||||
|
|
||||||
|
func _[P interface{ *int | *string }](p P) {
|
||||||
|
_ = *p // ERROR must have identical base types
|
||||||
|
}
|
||||||
|
|
||||||
|
type intPtr *int
|
||||||
|
|
||||||
|
func _[P interface{ *int | intPtr } ](p P) {
|
||||||
|
var _ int = *p
|
||||||
|
}
|
Loading…
Reference in a new issue