| 1 |
|
| 2 |
alias fun = mixin("(){}"); |
| 3 |
|
| 4 |
void test1() |
| 5 |
{ |
| 6 |
int x = 1; |
| 7 |
static immutable c = 2; |
| 8 |
|
| 9 |
fun(); |
| 10 |
foo!(mixin("int"))(); |
| 11 |
foo!(mixin("long*"))(); |
| 12 |
foo!(mixin("ST!(int, S.T)"))(); |
| 13 |
foo!(mixin(ST!(int, S.T)))(); |
| 14 |
|
| 15 |
int[mixin("string")] a1; |
| 16 |
int[mixin("5")] a2; |
| 17 |
int[mixin("c")] a3; |
| 18 |
int[] v1 = new int[mixin("3")]; |
| 19 |
auto v2 = new int[mixin("x")]; |
| 20 |
|
| 21 |
mixin(q{__traits(getMember, S, "T")}) ftv; |
| 22 |
|
| 23 |
alias T = int*; |
| 24 |
static assert(__traits(compiles, mixin("int"))); |
| 25 |
static assert(__traits(compiles, mixin(q{int[mixin("string")]}))); |
| 26 |
static assert(__traits(compiles, mixin(q{int[mixin("2")]}))); |
| 27 |
static assert(__traits(compiles, mixin(T))); |
| 28 |
static assert(__traits(compiles, mixin("int*"))); |
| 29 |
static assert(__traits(compiles, mixin(typeof(0)))); |
| 30 |
} |
| 31 |
|
| 32 |
struct S { alias T = float*; } |
| 33 |
|
| 34 |
struct ST(X,Y) {} |
| 35 |
|
| 36 |
void foo(alias t)() {} |
| 37 |
|
| 38 |
/**************************************************/ |
| 39 |
// https://issues.dlang.org/show_bug.cgi?id=21074 |
| 40 |
|
| 41 |
alias Byte = ubyte; |
| 42 |
alias Byte2(A) = ubyte; |
| 43 |
alias T0 = mixin(q{const(Byte)})*; |
| 44 |
alias T1 = mixin(q{const(Byte[1])})*; |
| 45 |
alias T2 = mixin(q{const(Byte2!int)})*; |
| 46 |
alias T3 = mixin(q{const(mixin(Byte2!int))})*; |
| 47 |
alias T4 = mixin(q{const(mixin("__traits(getMember, S, \"T\")"))})*; |
| 48 |
alias T5 = const(mixin(q{Byte}))*; |
| 49 |
alias T6 = const(mixin(q{immutable(Byte)}))*; |
| 50 |
alias T7 = const(mixin(q{shared(Byte)}))*; |
| 51 |
alias T8 = const(mixin(q{Byte*})); |
| 52 |
|
| 53 |
// the following tests now work |
| 54 |
static assert(is(T0 == const(ubyte)*)); |
| 55 |
static assert(is(T1 == const(ubyte[1])*)); |
| 56 |
static assert(is(T2 == const(ubyte)*)); |
| 57 |
static assert(is(T3 == const(ubyte)*)); |
| 58 |
static assert(is(T4 == const(float*)*)); |
| 59 |
static assert(is(T5 == const(ubyte)*)); |
| 60 |
static assert(is(T6 == immutable(ubyte)*)); |
| 61 |
static assert(is(T7 == const(shared(ubyte))*)); |
| 62 |
static assert(is(T8 == const(ubyte*))); |
| 63 |
|
| 64 |
// this doesn't work but I'll file a new issue |
| 65 |
/* |
| 66 |
alias T8 = mixin(q{immutable(__traits(getMember, S, "T"))})*; |
| 67 |
static assert(is(T8 == immutable(float*)*)); |
| 68 |
*/ |
| 69 |
|
| 70 |
/**************************************************/ |
| 71 |
// https://issues.dlang.org/show_bug.cgi?id=22356 |
| 72 |
|
| 73 |
mixin("void") func22356(int) { } |
| 74 |
static assert(is(typeof(&func22356) == void function(int))); |
| 75 |
|
| 76 |
static mixin("void") func22356_s(char) { } |
| 77 |
static assert(is(typeof(&func22356_s) == void function(char))); |
| 78 |
|
| 79 |
mixin("int")[2] func22356_2(int) { return [1, 2]; } |
| 80 |
static assert(is(typeof(&func22356_2) == int[2] function(int))); |
| 81 |
|
| 82 |
mixin("int") func22356tp(S, T)(S, T) { return 1; } |
| 83 |
static assert(is(typeof(&func22356tp!(char, float)) == int function(char, float) pure nothrow @nogc @safe)); |
| 84 |
|
| 85 |
mixin("int") x22356; |
| 86 |
static assert(is(typeof(x22356) == int)); |
| 87 |
|
| 88 |
mixin("int")** xpp22356; |
| 89 |
static assert(is(typeof(xpp22356) == int**)); |
| 90 |
|
| 91 |
mixin("int") y22356, z22356; |
| 92 |
static assert(is(typeof(y22356) == int) && is(typeof(z22356) == int)); |
| 93 |
|
| 94 |
// Already working but for completeness |
| 95 |
void test_statements_22356() |
| 96 |
{ |
| 97 |
mixin("void") func22356(int) { } |
| 98 |
static assert(is(typeof(&func22356) == void delegate(int) pure nothrow @nogc @safe)); |
| 99 |
|
| 100 |
static mixin("void") func22356_s(char) { } |
| 101 |
static assert(is(typeof(&func22356_s) == void function(char) pure nothrow @nogc @safe)); |
| 102 |
|
| 103 |
mixin("int")[2] func22356_2(int) { return [1, 2]; } |
| 104 |
static assert(is(typeof(&func22356_2) == int[2] delegate(int) pure nothrow @nogc @safe)); |
| 105 |
|
| 106 |
mixin("int") func22356tp(S, T)(S, T) { return 1; } |
| 107 |
static assert(is(typeof(&func22356tp!(char, float)) == int delegate(char, float) pure nothrow @nogc @safe)); |
| 108 |
|
| 109 |
mixin("int") x22356; |
| 110 |
static assert(is(typeof(x22356) == int)); |
| 111 |
|
| 112 |
mixin("int")** xpp22356; |
| 113 |
static assert(is(typeof(xpp22356) == int**)); |
| 114 |
|
| 115 |
mixin("int") y22356, z22356; |
| 116 |
static assert(is(typeof(y22356) == int) && is(typeof(z22356) == int)); |
| 117 |
} |
| 118 |
|
| 119 |
/**************************************************/ |
| 120 |
// https://issues.dlang.org/show_bug.cgi?id=22969 |
| 121 |
|
| 122 |
enum e = 0; |
| 123 |
alias a = mixin("e"); |