]> Cypherpunks repositories - gostls13.git/commit
go/types, types2: implement reverse type inference for function arguments
authorRobert Griesemer <gri@golang.org>
Wed, 12 Apr 2023 01:02:26 +0000 (18:02 -0700)
committerGopher Robot <gobot@golang.org>
Wed, 3 May 2023 18:47:48 +0000 (18:47 +0000)
commitea9097c9f75cf7149ebbcc3edc1161122bb15e5a
tree9374f08c69decf60db9a50767f3821fa11b265c5
parent57cb47209c655bdd7fb6d7effd5375e9b0fe90cf
go/types, types2: implement reverse type inference for function arguments

Allow function-typed function arguments to be generic and collect
their type parameters together with the callee's type parameters
(if any). Use a single inference step to infer the type arguments
for all type parameters simultaneously.

Requires Go 1.21 and that Config.EnableReverseTypeInference is set.
Does not yet support partially instantiated generic function arguments.
Not yet enabled in the compiler.

Known bug: inference may produce an incorrect result is the same
           generic function is passed twice in the same function
           call.

For #59338.

Change-Id: Ia1faa27a28c6353f0bbfd7f81feafc21bd36652c
Reviewed-on: https://go-review.googlesource.com/c/go/+/483935
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
14 files changed:
src/cmd/compile/internal/types2/api.go
src/cmd/compile/internal/types2/api_test.go
src/cmd/compile/internal/types2/call.go
src/cmd/compile/internal/types2/expr.go
src/cmd/compile/internal/types2/infer.go
src/go/types/api.go
src/go/types/api_test.go
src/go/types/call.go
src/go/types/check_test.go
src/go/types/expr.go
src/go/types/infer.go
src/internal/types/testdata/examples/inference2.go
src/internal/types/testdata/fixedbugs/issue59338a.go [new file with mode: 0644]
src/internal/types/testdata/fixedbugs/issue59338b.go [new file with mode: 0644]