aboutsummaryrefslogtreecommitdiff
path: root/test/typeparam/typelist.go
diff options
context:
space:
mode:
authorDan Scales <danscales@google.com>2021-03-29 16:07:18 -0700
committerDan Scales <danscales@google.com>2021-03-30 19:44:38 +0000
commit1318fb4a32371311688c6b868c3041f0501b6aeb (patch)
treec109d6aceab1e1373324cfd98e983febd4981262 /test/typeparam/typelist.go
parent3300390ec70c6b8e2392e4ab32342d426e2d3532 (diff)
downloadgo-1318fb4a32371311688c6b868c3041f0501b6aeb.tar.gz
go-1318fb4a32371311688c6b868c3041f0501b6aeb.zip
cmd/compile: handle partial type inference that doesn't require function args
Handle the case where types can be partially inferred for an instantiated function that is not immediately called. The key for the Inferred map is the CallExpr (if inferring types required the function arguments) or the IndexExpr (if types could be inferred without the function arguments). Added new tests for the case where the function isn't immediately called to typelist.go. Change-Id: I60f503ad67cd192da2f2002060229efd4930dc39 Reviewed-on: https://go-review.googlesource.com/c/go/+/305909 Trust: Dan Scales <danscales@google.com> Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Dan Scales <danscales@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'test/typeparam/typelist.go')
-rw-r--r--test/typeparam/typelist.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/test/typeparam/typelist.go b/test/typeparam/typelist.go
index 4ff3ce2f34..dd674cc889 100644
--- a/test/typeparam/typelist.go
+++ b/test/typeparam/typelist.go
@@ -62,3 +62,61 @@ func _[T interface{ type func(string) int }](f T) int {
func _[V any, T interface { type map[string]V }](p T) V {
return p["test"]
}
+
+
+// Testing partial and full type inference, including the case where the types can
+// be inferred without needing the types of the function arguments.
+
+func f0[A any, B interface{type C}, C interface{type D}, D interface{type A}](a A, b B, c C, d D)
+func _() {
+ f := f0[string]
+ f("a", "b", "c", "d")
+ f0("a", "b", "c", "d")
+}
+
+func f1[A any, B interface{type A}](a A, b B)
+func _() {
+ f := f1[int]
+ f(int(0), int(0))
+ f1(int(0), int(0))
+ f(0, 0)
+ f1(0, 0)
+}
+
+func f2[A any, B interface{type []A}](a A, b B)
+func _() {
+ f := f2[byte]
+ f(byte(0), []byte{})
+ f2(byte(0), []byte{})
+ f(0, []byte{})
+ // f2(0, []byte{}) - this one doesn't work
+}
+
+func f3[A any, B interface{type C}, C interface{type *A}](a A, b B, c C)
+func _() {
+ f := f3[int]
+ var x int
+ f(x, &x, &x)
+ f3(x, &x, &x)
+}
+
+func f4[A any, B interface{type []C}, C interface{type *A}](a A, b B, c C)
+func _() {
+ f := f4[int]
+ var x int
+ f(x, []*int{}, &x)
+ f4(x, []*int{}, &x)
+}
+
+func f5[A interface{type struct{b B; c C}}, B any, C interface{type *B}](x B) A
+func _() {
+ x := f5(1.2)
+ var _ float64 = x.b
+ var _ float64 = *x.c
+}
+
+func f6[A any, B interface{type struct{f []A}}](B) A
+func _() {
+ x := f6(struct{f []string}{})
+ var _ string = x
+}