Debian Codegraph @

src/internal/types/testdata/fixedbugs/issue66751.go

raw
1 // Copyright 2024 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 S struct{}
8
9 func (*S) m(int) {}
10
11 func f[A interface {
12 ~*B
13 m(C)
14 }, B, C any]() {
15 }
16
17 var _ = f[*S] // must be able to infer all remaining type arguments
18
19 // original test case from issue
20
21 type ptrTo[A any] interface{ ~*A }
22 type hasFoo[A any] interface{ foo(A) }
23 type both[A, B any] interface {
24 ptrTo[A]
25 hasFoo[B]
26 }
27
28 type fooer[A any] struct{}
29
30 func (f *fooer[A]) foo(A) {}
31
32 func withPtr[A ptrTo[B], B any]() {}
33 func withFoo[A hasFoo[B], B any]() {}
34 func withBoth[A both[B, C], B, C any]() {}
35
36 func _() {
37 withPtr[*fooer[int]]() // ok
38 withFoo[*fooer[int]]() // ok
39 withBoth[*fooer[int]]() // should be able to infer C
40 }
41
42 // related test case reported in issue
43
44 type X struct{}
45
46 func (x X) M() int { return 42 }
47
48 func CallM1[T interface{ M() R }, R any](t T) R {
49 return t.M()
50 }
51
52 func CallM2[T interface {
53 X
54 M() R
55 }, R any](t T) R {
56 return t.M()
57 }
58
59 func _() {
60 CallM1(X{}) // ok
61 CallM2(X{}) // should be able to infer R
62 }