Skip to content

Commit cf5fa2b

Browse files
committed
cmd/compile: be sure to export types mentioned in f.i.g. method signature
When a fully instantiated generic method is exported, be sure to also export the types in its signature. Updates #52279. Fixes #52286. Change-Id: Icc6bca05b01f914cf67faaf1bf184eaa5484f521 Reviewed-on: https://go-review.googlesource.com/c/go/+/405118 Run-TryBot: David Chase <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]> TryBot-Result: Gopher Robot <[email protected]> (cherry picked from commit 1284cc2) Reviewed-on: https://go-review.googlesource.com/c/go/+/405543 Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 8ed0e51 commit cf5fa2b

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

src/cmd/compile/internal/typecheck/crawler.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func (p *crawler) checkForFullyInst(t *types.Type) {
234234
for i, t1 := range t.RParams() {
235235
shapes[i] = Shapify(t1, i, baseType.RParams()[i])
236236
}
237-
for j := range t.Methods().Slice() {
237+
for j, tmethod := range t.Methods().Slice() {
238238
baseNname := baseType.Methods().Slice()[j].Nname.(*ir.Name)
239239
dictsym := MakeDictSym(baseNname.Sym(), t.RParams(), true)
240240
if dictsym.Def == nil {
@@ -255,6 +255,8 @@ func (p *crawler) checkForFullyInst(t *types.Type) {
255255
ImportedBody(methNode.Func)
256256
methNode.Func.SetExportInline(true)
257257
}
258+
// Make sure that any associated types are also exported. (See #52279)
259+
p.checkForFullyInst(tmethod.Type)
258260
}
259261
}
260262

test/fixedbugs/issue52279.dir/lib.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package lib
2+
3+
type FMap[K comparable, V comparable] map[K]V
4+
5+
//go:noinline
6+
func (m FMap[K, V]) Flip() FMap[V, K] {
7+
out := make(FMap[V, K])
8+
return out
9+
}
10+
11+
type MyType uint8
12+
13+
const (
14+
FIRST MyType = 0
15+
)
16+
17+
var typeStrs = FMap[MyType, string]{
18+
FIRST: "FIRST",
19+
}
20+
21+
func (self MyType) String() string {
22+
return typeStrs[self]
23+
}

test/fixedbugs/issue52279.dir/main.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package main
2+
3+
import "./lib"
4+
5+
func main() { lib.FIRST.String() }

test/fixedbugs/issue52279.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// rundir -G=3
2+
3+
// Copyright 2022 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 ignored

0 commit comments

Comments
 (0)