aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cmd/compile/internal/gc/obj.go4
-rw-r--r--test/typeparam/issue51245.go16
2 files changed, 20 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/gc/obj.go b/src/cmd/compile/internal/gc/obj.go
index 5353435ed1..74e4c0a890 100644
--- a/src/cmd/compile/internal/gc/obj.go
+++ b/src/cmd/compile/internal/gc/obj.go
@@ -217,6 +217,10 @@ func dumpGlobalConst(n ir.Node) {
if ir.ConstOverflow(v, t) {
return
}
+ } else {
+ // If the type of the constant is an instantiated generic, we need to emit
+ // that type so the linker knows about it. See issue 51245.
+ _ = reflectdata.TypeLinksym(t)
}
base.Ctxt.DwarfIntConst(base.Ctxt.Pkgpath, n.Sym().Name, types.TypeSymName(t), ir.IntVal(t, v))
}
diff --git a/test/typeparam/issue51245.go b/test/typeparam/issue51245.go
new file mode 100644
index 0000000000..bd4f7c5dc9
--- /dev/null
+++ b/test/typeparam/issue51245.go
@@ -0,0 +1,16 @@
+// build -gcflags=-G=3
+
+// 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 main
+
+type T[P any] int
+const C T[int] = 3
+
+type T2 int
+const C2 T2 = 9
+
+func main() {
+}