aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDan Scales <danscales@google.com>2021-09-06 16:25:43 -0700
committerDan Scales <danscales@google.com>2021-09-07 20:37:05 +0000
commit80783558b06741beaf41dbd198013fe3a13c9ad2 (patch)
tree5a2b8582afba8399f5df09c5b93818244870808f /test
parent23f4f0db682fad0c8d61a5b5cdbdbad4cf1cd41f (diff)
downloadgo-80783558b06741beaf41dbd198013fe3a13c9ad2.tar.gz
go-80783558b06741beaf41dbd198013fe3a13c9ad2.zip
cmd/compile: make sure imported instantiated types have their methods created
We should be putting a newly instantiated imported type in Instantiate/doInst onto the instTypeList, so its methods/dictionaries are instantiated. To do this, we needed a more general way to add a type to instTypeList, so add NeedInstType(), analogous to NeedRuntimeType(). This has the extra advantage that now all types created by the type substituter are added to instTypeList without any extra code, which was easy to forget. doInst() now correctly calls NeedInstType(). This is a bit aggressive, since a fully instantiated type in a generic function/method may never be used, if the generic method is never instantiated in the local package. But it should be fairly uncommon for a generic method to mention a fully instantiated type (but it does happen in this bug). Fixes both cases mentioned in the bug. Fixed #48185 Change-Id: I19b5012dfac17e306c8005f8595a648b0ab280d0 Reviewed-on: https://go-review.googlesource.com/c/go/+/347909 Trust: Dan Scales <danscales@google.com> Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'test')
-rw-r--r--test/typeparam/issue48185b.dir/a.go37
-rw-r--r--test/typeparam/issue48185b.dir/main.go18
-rw-r--r--test/typeparam/issue48185b.go7
3 files changed, 62 insertions, 0 deletions
diff --git a/test/typeparam/issue48185b.dir/a.go b/test/typeparam/issue48185b.dir/a.go
new file mode 100644
index 0000000000..9aed60cfae
--- /dev/null
+++ b/test/typeparam/issue48185b.dir/a.go
@@ -0,0 +1,37 @@
+// 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 a
+
+import (
+ "reflect"
+ "sync"
+)
+
+type addressableValue struct{ reflect.Value }
+
+type arshalers[Options, Coder any] struct {
+ fncVals []typedArshaler[Options, Coder]
+ fncCache sync.Map // map[reflect.Type]unmarshaler
+}
+type typedArshaler[Options, Coder any] struct {
+ typ reflect.Type
+ fnc func(Options, *Coder, addressableValue) error
+}
+
+type UnmarshalOptions1 struct {
+ // Unmarshalers is a list of type-specific unmarshalers to use.
+ Unmarshalers *arshalers[UnmarshalOptions1, Decoder1]
+}
+
+type Decoder1 struct {
+}
+
+func (a *arshalers[Options, Coder]) lookup(fnc func(Options, *Coder, addressableValue) error, t reflect.Type) func(Options, *Coder, addressableValue) error {
+ return fnc
+}
+
+func UnmarshalFuncV2[T any](fn func(UnmarshalOptions1, *Decoder1, T) error) *arshalers[UnmarshalOptions1, Decoder1] {
+ return &arshalers[UnmarshalOptions1, Decoder1]{}
+}
diff --git a/test/typeparam/issue48185b.dir/main.go b/test/typeparam/issue48185b.dir/main.go
new file mode 100644
index 0000000000..978e6ae585
--- /dev/null
+++ b/test/typeparam/issue48185b.dir/main.go
@@ -0,0 +1,18 @@
+// 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
+
+import (
+ "a"
+ "fmt"
+)
+
+func main() {
+ _ = a.UnmarshalOptions1{
+ Unmarshalers: a.UnmarshalFuncV2(func(opts a.UnmarshalOptions1, dec *a.Decoder1, val *interface{}) (err error) {
+ return fmt.Errorf("error")
+ }),
+ }
+}
diff --git a/test/typeparam/issue48185b.go b/test/typeparam/issue48185b.go
new file mode 100644
index 0000000000..76930e5e4f
--- /dev/null
+++ b/test/typeparam/issue48185b.go
@@ -0,0 +1,7 @@
+// rundir -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 ignored