methodvalues.go
695 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// RUN: llgo -o %t %s
// RUN: %t 2>&1 | FileCheck %s
// CHECK: 246
// CHECK-NEXT: T2.f()
// CHECK-NEXT: 10
// CHECK-NEXT: abc
package main
type T1 struct {
value int
}
func (t *T1) f(m int) int {
return m * t.value
}
func f1() {
var t T1
var f func(int) int = t.f
t.value = 2
println(f(123))
}
type T2 struct{}
func (T2) f() {
println("T2.f()")
}
func f2() {
var f func() = T2{}.f
f()
}
type T3 complex128
func (t T3) f() int {
return int(real(t))
}
func f3() {
var f func() int = T3(10).f
println(f())
}
type T4 string
func (t T4) f() string {
return string(t)
}
func f4() {
var f func() string = T4("abc").f
println(f())
}
func main() {
f1()
f2()
f3()
f4()
}