diff options
author | Rob Findley <rfindley@google.com> | 2021-07-16 20:50:18 -0400 |
---|---|---|
committer | Robert Findley <rfindley@google.com> | 2021-07-19 17:09:27 +0000 |
commit | 82f875d735fd07957a2224d2c73c677ddfdeef0d (patch) | |
tree | d9c91c2ceb479a9522cb8ceb89eff331b7e0e845 /src/go/types/expr.go | |
parent | 62f6f130fe1c6cbe9d2c1ea5160e83fb1cfa208a (diff) | |
download | go-82f875d735fd07957a2224d2c73c677ddfdeef0d.tar.gz go-82f875d735fd07957a2224d2c73c677ddfdeef0d.zip |
[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>
Diffstat (limited to 'src/go/types/expr.go')
-rw-r--r-- | src/go/types/expr.go | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/go/types/expr.go b/src/go/types/expr.go index 751a360890..b55f51185f 100644 --- a/src/go/types/expr.go +++ b/src/go/types/expr.go @@ -1400,13 +1400,24 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind { case typexpr: x.typ = &Pointer{base: x.typ} default: - if typ := asPointer(x.typ); typ != nil { - x.mode = variable - x.typ = typ.base - } else { - check.invalidOp(x, _InvalidIndirection, "cannot indirect %s", x) + var base Type + if !underIs(x.typ, func(u Type) bool { + p, _ := u.(*Pointer) + if p == nil { + 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 } + x.mode = variable + x.typ = base } case *ast.UnaryExpr: |