Source file
test/ken/intervar.go
1
2
3
4
5
6
7
8
9 package main
10
11 type Iputs interface {
12 puts (s string) string;
13 }
14
15
16
17 type Print struct {
18 whoami int;
19 put Iputs;
20 }
21
22 func (p *Print) dop() string {
23 r := " print " + string(p.whoami + '0')
24 return r + p.put.puts("abc");
25 }
26
27
28
29 type Bio struct {
30 whoami int;
31 put Iputs;
32 }
33
34 func (b *Bio) puts(s string) string {
35 r := " bio " + string(b.whoami + '0')
36 return r + b.put.puts(s);
37 }
38
39
40
41 type File struct {
42 whoami int;
43 put Iputs;
44 }
45
46 func (f *File) puts(s string) string {
47 return " file " + string(f.whoami + '0') + " -- " + s
48 }
49
50 func
51 main() {
52 p := new(Print);
53 b := new(Bio);
54 f := new(File);
55
56 p.whoami = 1;
57 p.put = b;
58
59 b.whoami = 2;
60 b.put = f;
61
62 f.whoami = 3;
63
64 r := p.dop();
65 expected := " print 1 bio 2 file 3 -- abc"
66 if r != expected {
67 panic(r + " != " + expected)
68 }
69 }
70
View as plain text