aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Chase <drchase@google.com>2022-05-10 12:52:52 -0400
committerDavid Chase <drchase@google.com>2022-05-10 19:15:31 +0000
commit1284cc24955487192fb7fb5aea934cb13fd1ae73 (patch)
tree1c7f27e15461d1a3614f8cd208c4fe16280e5c02
parent508cb32d4be3f71f2975ee978a474eb7d95d868a (diff)
downloadgo-1284cc24955487192fb7fb5aea934cb13fd1ae73.tar.gz
go-1284cc24955487192fb7fb5aea934cb13fd1ae73.zip
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. Fixes #52279. Change-Id: Icc6bca05b01f914cf67faaf1bf184eaa5484f521 Reviewed-on: https://go-review.googlesource.com/c/go/+/405118 Run-TryBot: David Chase <drchase@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
-rw-r--r--src/cmd/compile/internal/typecheck/crawler.go4
-rw-r--r--test/fixedbugs/issue52279.dir/lib.go23
-rw-r--r--test/fixedbugs/issue52279.dir/main.go5
-rw-r--r--test/fixedbugs/issue52279.go7
4 files changed, 38 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/typecheck/crawler.go b/src/cmd/compile/internal/typecheck/crawler.go
index 40b518983a..f14d885564 100644
--- a/src/cmd/compile/internal/typecheck/crawler.go
+++ b/src/cmd/compile/internal/typecheck/crawler.go
@@ -234,7 +234,7 @@ func (p *crawler) checkForFullyInst(t *types.Type) {
for i, t1 := range t.RParams() {
shapes[i] = Shapify(t1, i, baseType.RParams()[i])
}
- for j := range t.Methods().Slice() {
+ for j, tmethod := range t.Methods().Slice() {
baseNname := baseType.Methods().Slice()[j].Nname.(*ir.Name)
dictsym := MakeDictSym(baseNname.Sym(), t.RParams(), true)
if dictsym.Def == nil {
@@ -255,6 +255,8 @@ func (p *crawler) checkForFullyInst(t *types.Type) {
ImportedBody(methNode.Func)
methNode.Func.SetExportInline(true)
}
+ // Make sure that any associated types are also exported. (See #52279)
+ p.checkForFullyInst(tmethod.Type)
}
}
diff --git a/test/fixedbugs/issue52279.dir/lib.go b/test/fixedbugs/issue52279.dir/lib.go
new file mode 100644
index 0000000000..e20de30bd5
--- /dev/null
+++ b/test/fixedbugs/issue52279.dir/lib.go
@@ -0,0 +1,23 @@
+package lib
+
+type FMap[K comparable, V comparable] map[K]V
+
+//go:noinline
+func (m FMap[K, V]) Flip() FMap[V, K] {
+ out := make(FMap[V, K])
+ return out
+}
+
+type MyType uint8
+
+const (
+ FIRST MyType = 0
+)
+
+var typeStrs = FMap[MyType, string]{
+ FIRST: "FIRST",
+}
+
+func (self MyType) String() string {
+ return typeStrs[self]
+}
diff --git a/test/fixedbugs/issue52279.dir/main.go b/test/fixedbugs/issue52279.dir/main.go
new file mode 100644
index 0000000000..8c7e069c5b
--- /dev/null
+++ b/test/fixedbugs/issue52279.dir/main.go
@@ -0,0 +1,5 @@
+package main
+
+import "./lib"
+
+func main() { lib.FIRST.String() }
diff --git a/test/fixedbugs/issue52279.go b/test/fixedbugs/issue52279.go
new file mode 100644
index 0000000000..aefbe67310
--- /dev/null
+++ b/test/fixedbugs/issue52279.go
@@ -0,0 +1,7 @@
+// rundir
+
+// Copyright 2022 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 ignored