1 // Copyright 2022 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package p
6
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) {}
11
12 func f2[M2 map[string]int](m2 M2) {
13 f1(m2)
14 }
15
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
33 // test case from issue
34
35 func Copy[MC ~map[KC]VC, KC comparable, VC any](dst, src MC) {
36 for k, v := range src {
37 dst[k] = v
38 }
39 }
40
41 func Merge[MM ~map[KM]VM, KM comparable, VM any](ms ...MM) MM {
42 result := MM{}
43 for _, m := range ms {
44 Copy(result, m)
45 }
46 return result
47 }
48
View as plain text