Source file
test/typeparam/issue50690c.go
1
2
3
4
5
6
7 package main
8
9 import (
10 "fmt"
11 )
12
13 type Printer[T ~string] struct {
14 PrintFn func(T)
15 }
16
17 func Print[T ~string](s T) {
18 fmt.Println(s)
19 }
20
21 func PrintWithPrinter[T ~string, S interface {
22 ~struct {
23 ID T
24 PrintFn_ func(T)
25 }
26 PrintFn() func(T)
27 }](message T, obj S) {
28 obj.PrintFn()(message)
29 }
30
31 func main() {
32 PrintWithPrinter(
33 "Hello, world.",
34 StructWithPrinter{ID: "fake", PrintFn_: Print[string]},
35 )
36 }
37
38 type StructWithPrinter struct {
39 ID string
40 PrintFn_ func(string)
41 }
42
43
44
45
46
47
48 func (s StructWithPrinter) PrintFn() func(string) {
49 return s.PrintFn_
50 }
51
View as plain text