summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.test/compilable/mixintype2.d
blob: a61adc570fa885de50087f3514eea647447e2e80 (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
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
121
122
123

alias fun = mixin("(){}");

void test1()
{
    int x = 1;
    static immutable c = 2;

    fun();
    foo!(mixin("int"))();
    foo!(mixin("long*"))();
    foo!(mixin("ST!(int, S.T)"))();
    foo!(mixin(ST!(int, S.T)))();

    int[mixin("string")] a1;
    int[mixin("5")] a2;
    int[mixin("c")] a3;
    int[] v1 = new int[mixin("3")];
    auto v2 = new int[mixin("x")];

    mixin(q{__traits(getMember, S, "T")}) ftv;

    alias T = int*;
    static assert(__traits(compiles, mixin("int")));
    static assert(__traits(compiles, mixin(q{int[mixin("string")]})));
    static assert(__traits(compiles, mixin(q{int[mixin("2")]})));
    static assert(__traits(compiles, mixin(T)));
    static assert(__traits(compiles, mixin("int*")));
    static assert(__traits(compiles, mixin(typeof(0))));
}

struct S { alias T = float*; }

struct ST(X,Y) {}

void foo(alias t)() {}

/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=21074

alias Byte = ubyte;
alias Byte2(A) = ubyte;
alias T0 = mixin(q{const(Byte)})*;
alias T1 = mixin(q{const(Byte[1])})*;
alias T2 = mixin(q{const(Byte2!int)})*;
alias T3 = mixin(q{const(mixin(Byte2!int))})*;
alias T4 = mixin(q{const(mixin("__traits(getMember, S, \"T\")"))})*;
alias T5 = const(mixin(q{Byte}))*;
alias T6 = const(mixin(q{immutable(Byte)}))*;
alias T7 = const(mixin(q{shared(Byte)}))*;
alias T8 = const(mixin(q{Byte*}));

// the following tests now work
static assert(is(T0 == const(ubyte)*));
static assert(is(T1 == const(ubyte[1])*));
static assert(is(T2 == const(ubyte)*));
static assert(is(T3 == const(ubyte)*));
static assert(is(T4 == const(float*)*));
static assert(is(T5 == const(ubyte)*));
static assert(is(T6 == immutable(ubyte)*));
static assert(is(T7 == const(shared(ubyte))*));
static assert(is(T8 == const(ubyte*)));

// this doesn't work but I'll file a new issue
/*
alias T8 = mixin(q{immutable(__traits(getMember, S, "T"))})*;
static assert(is(T8 == immutable(float*)*));
*/

/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22356

mixin("void") func22356(int) { }
static assert(is(typeof(&func22356) == void function(int)));

static mixin("void") func22356_s(char) { }
static assert(is(typeof(&func22356_s) == void function(char)));

mixin("int")[2] func22356_2(int) { return [1, 2]; }
static assert(is(typeof(&func22356_2) == int[2] function(int)));

mixin("int") func22356tp(S, T)(S, T) { return 1; }
static assert(is(typeof(&func22356tp!(char, float)) == int function(char, float) pure nothrow @nogc @safe));

mixin("int") x22356;
static assert(is(typeof(x22356) == int));

mixin("int")** xpp22356;
static assert(is(typeof(xpp22356) == int**));

mixin("int") y22356, z22356;
static assert(is(typeof(y22356) == int) && is(typeof(z22356) == int));

// Already working but for completeness
void test_statements_22356()
{
    mixin("void") func22356(int) { }
    static assert(is(typeof(&func22356) == void delegate(int) pure nothrow @nogc @safe));

    static mixin("void") func22356_s(char) { }
    static assert(is(typeof(&func22356_s) == void function(char) pure nothrow @nogc @safe));

    mixin("int")[2] func22356_2(int) { return [1, 2]; }
    static assert(is(typeof(&func22356_2) == int[2] delegate(int) pure nothrow @nogc @safe));

    mixin("int") func22356tp(S, T)(S, T) { return 1; }
    static assert(is(typeof(&func22356tp!(char, float)) == int delegate(char, float) pure nothrow @nogc @safe));

    mixin("int") x22356;
    static assert(is(typeof(x22356) == int));

    mixin("int")** xpp22356;
    static assert(is(typeof(xpp22356) == int**));

    mixin("int") y22356, z22356;
    static assert(is(typeof(y22356) == int) && is(typeof(z22356) == int));
}

/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22969

enum e = 0;
alias a = mixin("e");