]> Cypherpunks.ru repositories - gostls13.git/commitdiff
go/types, types2: add additional tests using core types during unification
authorRobert Griesemer <gri@golang.org>
Sat, 12 Feb 2022 18:24:38 +0000 (10:24 -0800)
committerRobert Griesemer <gri@golang.org>
Sun, 13 Feb 2022 02:11:11 +0000 (02:11 +0000)
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>
src/cmd/compile/internal/types2/testdata/fixedbugs/issue50755.go2
src/cmd/compile/internal/types2/unify.go
src/go/types/testdata/fixedbugs/issue50755.go2
src/go/types/unify.go

index 9fcb6d085e7af99884e34a1489bcfeb27d121738..afc7b2414cb37ca8fe633fc8058bb3d7541cebc5 100644 (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) {
index 3a28b09342c6bbf2a5f6b54d40dc65932274618f..50edce98810b3be93a370455492af67024de7673 100644 (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
index 9fcb6d085e7af99884e34a1489bcfeb27d121738..afc7b2414cb37ca8fe633fc8058bb3d7541cebc5 100644 (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) {
index 9ed09cdbc560aff2880bf1153ec5ee35d85d57bf..ac904d6d6bf6bc5b8edcde8d5e17d7f016b54256 100644 (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