blob: 7577bcb89d388f7d1f3a3fb525eb96bebe20727d (
plain)
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
65
66
67
68
69
70
71
72
73
74
75
|
struct Base {
}
interface Foo {
parent Foo2
thing(mut b Base, value i64) string
}
interface Foo2 {
thing(mut b Base, value i64) string
}
struct Bar {
parent Foo2
}
struct Bar2 {}
fn (f Bar) thing(mut b Base, value i64) string {
return 'bar'
}
fn (f Bar2) thing(mut b Base, value i64) string {
return 'bar2'
}
struct SubBar {
parent Foo2 = Bar2{}
}
fn (f SubBar) thing(mut b Base, value i64) string {
return 'subbar'
}
fn test_interface_nested_field() {
mut foo_group := []Foo2{}
foo_group << Bar2{}
foo_group << SubBar{}
mut b := Base{}
mut ret := []string{}
for foo in foo_group {
println(foo.thing(mut b, 22))
ret << foo.thing(mut b, 22)
}
assert ret.len == 2
assert ret[0] == 'bar2'
assert ret[1] == 'subbar'
}
interface Root {
v View
}
struct MyRoot {
v View
}
interface View {
render() int
}
struct MyView {}
fn (m MyView) render() int {
return 24
}
fn receive_root(r Root) int {
return r.v.render()
}
fn test_nested_interface_fields() {
assert receive_root(MyRoot{MyView{}}) == 24
}
|