-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathintfs.nt
120 lines (100 loc) · 2.92 KB
/
intfs.nt
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
module intfs;
macro import std.macro.assert;
import helpers;
interface A {
string foo();
}
interface B {
string bar();
}
interface C : A, B {
string baz();
}
class X : C {
override string foo() { return "X.foo"; }
override string bar() { return "X.bar"; }
override string baz() { return "X.baz"; }
}
interface D {
string qux();
}
class Y : X, D {
this() { }
override string foo() { return "Y.foo"; }
override string bar() { return "Y.bar"; }
override string baz() { return "Y.baz"; }
override string qux() { return "Y.qux"; }
}
void main() {
Y y = new Y;
void dump() {
print("contents of $(cast(size_t) y):");
for (i in 0 .. 5) {
print(" $i: $((cast(size_t*) y)[i])");
}
}
// dump;
size_t refs() { return (cast(size_t*) y)[1]; }
assert(refs == 1);
assert(y.foo == "Y.foo");
assert(y.bar == "Y.bar");
assert(y.baz == "Y.baz");
assert(y.qux == "Y.qux");
assert(y.instanceOf(Y).foo == "Y.foo");
assert(y.instanceOf(X).foo == "Y.foo");
assert(y.instanceOf(A).foo == "Y.foo");
assert(y.instanceOf(B).bar == "Y.bar");
assert(y.instanceOf(C).baz == "Y.baz");
{
X x = y;
assert(x.foo == "Y.foo");
assert(x.bar == "Y.bar");
assert(x.baz == "Y.baz");
assert(x.instanceOf(Y).foo == "Y.foo");
assert(x.instanceOf(X).foo == "Y.foo");
assert(x.instanceOf(A).foo == "Y.foo");
assert(x.instanceOf(B).bar == "Y.bar");
assert(x.instanceOf(C).baz == "Y.baz");
assert(refs == 1);
C c = x;
assert(refs == 1);
assert(c.foo == "Y.foo");
assert(c.bar == "Y.bar");
assert(c.baz == "Y.baz");
assert(c.instanceOf(Y).foo == "Y.foo");
assert(c.instanceOf(X).foo == "Y.foo");
assert(c.instanceOf(A).foo == "Y.foo");
assert(c.instanceOf(B).bar == "Y.bar");
assert(c.instanceOf(C).baz == "Y.baz");
assert(refs == 1);
B b = c;
assert(b.bar == "Y.bar");
assert(b.instanceOf(Y).foo == "Y.foo");
assert(b.instanceOf(X).foo == "Y.foo");
assert(b.instanceOf(A).foo == "Y.foo");
assert(b.instanceOf(B).bar == "Y.bar");
assert(b.instanceOf(C).baz == "Y.baz");
A a = c;
assert(a.foo == "Y.foo");
assert(a.instanceOf(Y).foo == "Y.foo");
assert(a.instanceOf(X).foo == "Y.foo");
assert(a.instanceOf(A).foo == "Y.foo");
assert(a.instanceOf(B).bar == "Y.bar");
assert(a.instanceOf(C).baz == "Y.baz");
}
assert(refs == 1);
{
B b2 = y;
assert(b2.bar == "Y.bar");
// FIXME why does b3 grab a ref?
B b3 = b2;
assert(b3.bar == "Y.bar");
{
mut B b1 = y;
assert(b1.instanceOf(Y));
mut nullable B b2 = y.instanceOf(B);
assert(b2.instanceOf(Y));
}
}
assert(refs == 1);
}