summaryrefslogtreecommitdiff
path: root/src/internal/types/testdata/examples/inference2.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2023-05-09 12:38:40 -0700
committerGopher Robot <gobot@golang.org>2023-05-16 23:01:33 +0000
commit099f5a985f9db17c9d1048e6afb6fd162f41256c (patch)
tree192e37b83fba33456d8593c835f0746c71dec00a /src/internal/types/testdata/examples/inference2.go
parent522be4e01000abe771362984f8d351c8452cceef (diff)
downloadgo-git-099f5a985f9db17c9d1048e6afb6fd162f41256c.tar.gz
go/types, types2: permit partially instantiated functions as function arguments
This CL changes Checker.genericExprList such that it collects partially instantiated generic functions together with their (partial) type argument (and corresponding) expression lists, instead of trying to infer the missing type arguments in place or to report an error. Special care is being taken to explictly record expression types where needed (because we can't use one of the usual expr evaluators which takes care of that), or to track the correct instance expression for later recording with Checker.arguments. The resulting generic expression list is passed to Checker.arguments which is changed to accept explicit partial type argument (and corresponding) expression lists. The provided type arguments are fed into type inference, matching up with their respective type parameters (which were collected already, before this CL). If type inference is successful, the instantiated functions are recorded as needed. For now, the type argument expression lists are collected and passed along but not yet used. We may use them eventually for better error reporting. Fixes #59958. For #59338. Change-Id: I26db47ef3546e64553da49d62b23cd3ef9e2b549 Reviewed-on: https://go-review.googlesource.com/c/go/+/494116 Reviewed-by: Robert Findley <rfindley@google.com> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Robert Griesemer <gri@google.com>
Diffstat (limited to 'src/internal/types/testdata/examples/inference2.go')
-rw-r--r--src/internal/types/testdata/examples/inference2.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/internal/types/testdata/examples/inference2.go b/src/internal/types/testdata/examples/inference2.go
index 4eeb6d1b05..aa2475b741 100644
--- a/src/internal/types/testdata/examples/inference2.go
+++ b/src/internal/types/testdata/examples/inference2.go
@@ -88,3 +88,13 @@ func _() {
g5(f6, f7)
g6(f1, f1)
}
+
+// Argument passing of partially instantiated functions
+func h(func(int, string), func(string, int)) {}
+
+func p[P, Q any](P, Q) {}
+
+func _() {
+ h(p, p)
+ h(p[int], p[string])
+}