]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix function contains no TParam in generic function
authorkorzhao <korzhao95@gmail.com>
Wed, 25 Aug 2021 08:01:49 +0000 (16:01 +0800)
committerDan Scales <danscales@google.com>
Wed, 25 Aug 2021 19:06:16 +0000 (19:06 +0000)
Fixes #47948

Change-Id: I446a9548265d195ae4d88aff6b1361474d1b6214
Reviewed-on: https://go-review.googlesource.com/c/go/+/344910
Trust: Alexander Rakoczy <alex@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Alexander Rakoczy <alex@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
src/cmd/compile/internal/typecheck/subr.go
test/typeparam/issue47948.go [new file with mode: 0644]

index b9cdcf10f2ce47397dfb98e4c051741c004f17c3..8d053565436a2d256a37600510a94042e79034a1 100644 (file)
@@ -1051,7 +1051,8 @@ func (ts *Tsubster) typ1(t *types.Type) *types.Type {
        var targsChanged bool
        var forw *types.Type
 
-       if t.Sym() != nil {
+       if t.Sym() != nil && t.HasTParam() {
+               // Need to test for t.HasTParam() again because of special TFUNC case above.
                // Translate the type params for this type according to
                // the tparam/targs mapping from subst.
                neededTargs = make([]*types.Type, len(t.RParams()))
diff --git a/test/typeparam/issue47948.go b/test/typeparam/issue47948.go
new file mode 100644 (file)
index 0000000..8e5df81
--- /dev/null
@@ -0,0 +1,18 @@
+// 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 main
+
+type fun func()
+
+func F[T any]() {
+       _ = fun(func() {
+
+       })
+}
+func main() {
+       F[int]()
+}