1
0
mirror of https://github.com/golang/go synced 2024-11-26 16:16:57 -07:00

go/types, types2: add additional tests using core types during unification

This change adds tests that use a type parameter's core type during
function argument type inference, not just during constraint type
inference.

Also, fix a typo in a comment.

For #50755.

Change-Id: I0c3196bdce5338341e0b6dfd7c63efb2e43ace25
Reviewed-on: https://go-review.googlesource.com/c/go/+/385376
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Robert Griesemer 2022-02-12 10:24:38 -08:00
parent f03ab0e014
commit 5bd734839d
4 changed files with 46 additions and 6 deletions

View File

@ -4,12 +4,32 @@
package p
func f1[M1 map[K1]int, K1 comparable](m1 M1) {}
// The core type of M2 unifies with the type of m1
// during function argument type inference.
// M2's constraint is unnamed.
func f1[K1 comparable, E1 any](m1 map[K1]E1) {}
func f2[M2 map[K2]int, K2 comparable](m2 M2) {
func f2[M2 map[string]int](m2 M2) {
f1(m2)
}
// The core type of M3 unifies with the type of m1
// during function argument type inference.
// M3's constraint is named.
type Map3 map[string]int
func f3[M3 Map3](m3 M3) {
f1(m3)
}
// The core type of M5 unifies with the core type of M4
// during constraint type inference.
func f4[M4 map[K4]int, K4 comparable](m4 M4) {}
func f5[M5 map[K5]int, K5 comparable](m5 M5) {
f4(m5)
}
// test case from issue
func Copy[MC ~map[KC]VC, KC comparable, VC any](dst, src MC) {

View File

@ -27,7 +27,7 @@ import (
// parameter P ("x" side), but the argument type P must be left alone so
// that unification resolves the type parameter P to P.
//
// For bidirection unification, both sets are provided. This enables
// For bidirectional unification, both sets are provided. This enables
// unification to go from argument to parameter type and vice versa.
// For constraint type inference, we use bidirectional unification
// where both the x and y type parameters are identical. This is done

View File

@ -4,12 +4,32 @@
package p
func f1[M1 map[K1]int, K1 comparable](m1 M1) {}
// The core type of M2 unifies with the type of m1
// during function argument type inference.
// M2's constraint is unnamed.
func f1[K1 comparable, E1 any](m1 map[K1]E1) {}
func f2[M2 map[K2]int, K2 comparable](m2 M2) {
func f2[M2 map[string]int](m2 M2) {
f1(m2)
}
// The core type of M3 unifies with the type of m1
// during function argument type inference.
// M3's constraint is named.
type Map3 map[string]int
func f3[M3 Map3](m3 M3) {
f1(m3)
}
// The core type of M5 unifies with the core type of M4
// during constraint type inference.
func f4[M4 map[K4]int, K4 comparable](m4 M4) {}
func f5[M5 map[K5]int, K5 comparable](m5 M5) {
f4(m5)
}
// test case from issue
func Copy[MC ~map[KC]VC, KC comparable, VC any](dst, src MC) {

View File

@ -27,7 +27,7 @@ import (
// parameter P ("x" side), but the argument type P must be left alone so
// that unification resolves the type parameter P to P.
//
// For bidirection unification, both sets are provided. This enables
// For bidirectional unification, both sets are provided. This enables
// unification to go from argument to parameter type and vice versa.
// For constraint type inference, we use bidirectional unification
// where both the x and y type parameters are identical. This is done