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 type A1 [2]uint64
8 type A2 [2]uint64
9
10 func (a A1) m() A1 { return a }
11 func (a A2) m() A2 { return a }
12
13 func f[B any, T interface {
14 A1 | A2
15 m() T
16 }](v T) {
17 }
18
19 func _() {
20 var v A2
21 // Use function type inference to infer type A2 for T.
22 // Don't use constraint type inference before function
23 // type inference for typed arguments, otherwise it would
24 // infer type [2]uint64 for T which doesn't have method m
25 // (was the bug).
26 f[int](v)
27 }
28
29 // Keep using constraint type inference before function type
30 // inference for untyped arguments so we infer type float64
31 // for E below, and not int (which would not work).
32 func g[S ~[]E, E any](S, E) {}
33
34 func _() {
35 var s []float64
36 g[[]float64](s, 0)
37 }
38
39 // Keep using constraint type inference after function
40 // type inference for untyped arguments so we infer
41 // missing type arguments for which we only have the
42 // untyped arguments as starting point.
43 func h[E any, R []E](v E) R { return R{v} }
44 func _() []int { return h(0) }
45
View as plain text