| 1 |
// https://issues.dlang.org/show_bug.cgi?id=11294 |
| 2 |
|
| 3 |
string result; |
| 4 |
|
| 5 |
extern(C) void rt_finalize(void *ptr, bool det=true); |
| 6 |
void clear(T)(T obj) if (is(T == class)) |
| 7 |
{ |
| 8 |
rt_finalize(cast(void*)obj); |
| 9 |
} |
| 10 |
|
| 11 |
class A |
| 12 |
{ |
| 13 |
~this() { result ~= "A"; } |
| 14 |
string dummy = "0"; |
| 15 |
} |
| 16 |
|
| 17 |
class B |
| 18 |
{ |
| 19 |
A a; |
| 20 |
string dummy = "0"; |
| 21 |
alias a this; |
| 22 |
~this() { result ~= "B"; } |
| 23 |
} |
| 24 |
|
| 25 |
void test11294() |
| 26 |
{ |
| 27 |
auto a = new A; |
| 28 |
auto b = new B; |
| 29 |
b.a = a; |
| 30 |
result ~= b.dummy; |
| 31 |
clear(b); |
| 32 |
result ~= a.dummy; |
| 33 |
result ~= "END"; |
| 34 |
clear(a); |
| 35 |
|
| 36 |
assert(result == "0B0ENDA"); |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
// https://issues.dlang.org/show_bug.cgi?id=13392 |
| 41 |
void foo(T)(T t) |
| 42 |
{ |
| 43 |
void* p = cast(void*) t; //Callas alias this |
| 44 |
} |
| 45 |
|
| 46 |
class X {} |
| 47 |
|
| 48 |
class Y |
| 49 |
{ |
| 50 |
alias a this; |
| 51 |
@property X a(){assert(0);} //Here |
| 52 |
} |
| 53 |
|
| 54 |
void test13392() |
| 55 |
{ |
| 56 |
foo(B.init); |
| 57 |
} |
| 58 |
|
| 59 |
void main() |
| 60 |
{ |
| 61 |
test11294(); |
| 62 |
test13392(); |
| 63 |
} |