Skip to content

Commit 08d4cc2

Browse files
wdvxdr1123danscales
authored andcommitted
cmd/compile: fix stencil call expression.
Fixes: #47878 Change-Id: I369350813726fd518b4eab2b98f43bf031a6dee6 Reviewed-on: https://go-review.googlesource.com/c/go/+/344210 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 099b819 commit 08d4cc2

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,13 @@ func (subst *subster) node(n ir.Node) ir.Node {
10481048
case ir.OCLOSURE:
10491049
transformCall(call)
10501050

1051+
case ir.ODEREF, ir.OINDEX, ir.OINDEXMAP, ir.ORECV:
1052+
// Transform a call that was delayed because of the
1053+
// use of typeparam inside an expression that required
1054+
// a pointer dereference, array indexing, map indexing,
1055+
// or channel receive to compute function value.
1056+
transformCall(call)
1057+
10511058
case ir.OFUNCINST:
10521059
// A call with an OFUNCINST will get transformed
10531060
// in stencil() once we have created & attached the

test/typeparam/issue47878.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 main
8+
9+
type Src1[T any] func() Src1[T]
10+
11+
func (s *Src1[T]) Next() {
12+
*s = (*s)()
13+
}
14+
15+
type Src2[T any] []func() Src2[T]
16+
17+
func (s Src2[T]) Next() {
18+
_ = s[0]()
19+
}
20+
21+
type Src3[T comparable] map[T]func() Src3[T]
22+
23+
func (s Src3[T]) Next() {
24+
var a T
25+
_ = s[a]()
26+
}
27+
28+
type Src4[T any] chan func() T
29+
30+
func (s Src4[T]) Next() {
31+
_ = (<-s)()
32+
}
33+
34+
func main() {
35+
var src1 Src1[int]
36+
src1.Next()
37+
38+
var src2 Src2[int]
39+
src2.Next()
40+
41+
var src3 Src3[string]
42+
src3.Next()
43+
44+
var src4 Src4[int]
45+
src4.Next()
46+
}

0 commit comments

Comments
 (0)