Skip to content

Commit b602dae

Browse files
korzhaodanscales
authored andcommitted
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 <[email protected]> Trust: Dan Scales <[email protected]> Trust: Keith Randall <[email protected]> Run-TryBot: Dan Scales <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent 7b38dd8 commit b602dae

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/cmd/compile/internal/noder/expr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func (g *irgen) selectorExpr(pos src.XPos, typ types2.Type, expr *syntax.Selecto
270270
if types2.AsInterface(recvType.Underlying()) != nil {
271271
fieldType := n.X.Type()
272272
for _, ix := range index[:len(index)-1] {
273-
fieldType = fieldType.Field(ix).Type
273+
fieldType = deref(fieldType).Field(ix).Type
274274
}
275275
if fieldType.Kind() == types.TTYPEPARAM {
276276
n.Selection = fieldType.Bound().AllMethods().Index(last)

test/typeparam/issue48056.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// compile -G=3
2+
3+
// Copyright 2021 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package p
8+
9+
type B[T any] interface {
10+
Work()
11+
}
12+
type BImpl[T any] struct{}
13+
14+
func (b *BImpl[T]) Work() {
15+
}
16+
17+
type A[T any] struct {
18+
B[T]
19+
}
20+
21+
func f[T any]() {
22+
s := &A[T]{
23+
&BImpl[T]{},
24+
}
25+
// golang.org/issue/48056
26+
s.Work()
27+
}

0 commit comments

Comments
 (0)