Skip to content

Commit 5bd7348

Browse files
committed
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 <[email protected]> Run-TryBot: Robert Griesemer <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent f03ab0e commit 5bd7348

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

src/cmd/compile/internal/types2/testdata/fixedbugs/issue50755.go2

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,32 @@
44

55
package p
66

7-
func f1[M1 map[K1]int, K1 comparable](m1 M1) {}
7+
// The core type of M2 unifies with the type of m1
8+
// during function argument type inference.
9+
// M2's constraint is unnamed.
10+
func f1[K1 comparable, E1 any](m1 map[K1]E1) {}
811

9-
func f2[M2 map[K2]int, K2 comparable](m2 M2) {
12+
func f2[M2 map[string]int](m2 M2) {
1013
f1(m2)
1114
}
1215

16+
// The core type of M3 unifies with the type of m1
17+
// during function argument type inference.
18+
// M3's constraint is named.
19+
type Map3 map[string]int
20+
21+
func f3[M3 Map3](m3 M3) {
22+
f1(m3)
23+
}
24+
25+
// The core type of M5 unifies with the core type of M4
26+
// during constraint type inference.
27+
func f4[M4 map[K4]int, K4 comparable](m4 M4) {}
28+
29+
func f5[M5 map[K5]int, K5 comparable](m5 M5) {
30+
f4(m5)
31+
}
32+
1333
// test case from issue
1434

1535
func Copy[MC ~map[KC]VC, KC comparable, VC any](dst, src MC) {

src/cmd/compile/internal/types2/unify.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
// parameter P ("x" side), but the argument type P must be left alone so
2828
// that unification resolves the type parameter P to P.
2929
//
30-
// For bidirection unification, both sets are provided. This enables
30+
// For bidirectional unification, both sets are provided. This enables
3131
// unification to go from argument to parameter type and vice versa.
3232
// For constraint type inference, we use bidirectional unification
3333
// where both the x and y type parameters are identical. This is done

src/go/types/testdata/fixedbugs/issue50755.go2

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,32 @@
44

55
package p
66

7-
func f1[M1 map[K1]int, K1 comparable](m1 M1) {}
7+
// The core type of M2 unifies with the type of m1
8+
// during function argument type inference.
9+
// M2's constraint is unnamed.
10+
func f1[K1 comparable, E1 any](m1 map[K1]E1) {}
811

9-
func f2[M2 map[K2]int, K2 comparable](m2 M2) {
12+
func f2[M2 map[string]int](m2 M2) {
1013
f1(m2)
1114
}
1215

16+
// The core type of M3 unifies with the type of m1
17+
// during function argument type inference.
18+
// M3's constraint is named.
19+
type Map3 map[string]int
20+
21+
func f3[M3 Map3](m3 M3) {
22+
f1(m3)
23+
}
24+
25+
// The core type of M5 unifies with the core type of M4
26+
// during constraint type inference.
27+
func f4[M4 map[K4]int, K4 comparable](m4 M4) {}
28+
29+
func f5[M5 map[K5]int, K5 comparable](m5 M5) {
30+
f4(m5)
31+
}
32+
1333
// test case from issue
1434

1535
func Copy[MC ~map[KC]VC, KC comparable, VC any](dst, src MC) {

src/go/types/unify.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
// parameter P ("x" side), but the argument type P must be left alone so
2828
// that unification resolves the type parameter P to P.
2929
//
30-
// For bidirection unification, both sets are provided. This enables
30+
// For bidirectional unification, both sets are provided. This enables
3131
// unification to go from argument to parameter type and vice versa.
3232
// For constraint type inference, we use bidirectional unification
3333
// where both the x and y type parameters are identical. This is done

0 commit comments

Comments
 (0)