From: korzhao Date: Mon, 30 Aug 2021 09:09:51 +0000 (+0800) Subject: cmd/compile: fix error when revcType is ptr in selectorExpr X-Git-Tag: go1.18beta1~1579 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b602daea1b94a8a578bafdc6ef6336c07fe63300;p=gostls13.git cmd/compile: fix error when revcType is ptr in selectorExpr Fixes #48056 Change-Id: I13ca4caadbabf02084f66ab28b4cf0c4a3705370 Reviewed-on: https://go-review.googlesource.com/c/go/+/346049 Reviewed-by: Dan Scales Trust: Dan Scales Trust: Keith Randall Run-TryBot: Dan Scales TryBot-Result: Go Bot --- diff --git a/src/cmd/compile/internal/noder/expr.go b/src/cmd/compile/internal/noder/expr.go index 58637dca39..0e5257d7cf 100644 --- a/src/cmd/compile/internal/noder/expr.go +++ b/src/cmd/compile/internal/noder/expr.go @@ -270,7 +270,7 @@ func (g *irgen) selectorExpr(pos src.XPos, typ types2.Type, expr *syntax.Selecto if types2.AsInterface(recvType.Underlying()) != nil { fieldType := n.X.Type() for _, ix := range index[:len(index)-1] { - fieldType = fieldType.Field(ix).Type + fieldType = deref(fieldType).Field(ix).Type } if fieldType.Kind() == types.TTYPEPARAM { n.Selection = fieldType.Bound().AllMethods().Index(last) diff --git a/test/typeparam/issue48056.go b/test/typeparam/issue48056.go new file mode 100644 index 0000000000..8d1c3eff64 --- /dev/null +++ b/test/typeparam/issue48056.go @@ -0,0 +1,27 @@ +// compile -G=3 + +// 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 B[T any] interface { + Work() +} +type BImpl[T any] struct{} + +func (b *BImpl[T]) Work() { +} + +type A[T any] struct { + B[T] +} + +func f[T any]() { + s := &A[T]{ + &BImpl[T]{}, + } + // golang.org/issue/48056 + s.Work() +}