File: fix22291.d

package info (click to toggle)
gcc-arm-none-eabi 15%3A14.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,099,328 kB
  • sloc: cpp: 3,627,108; ansic: 2,571,498; ada: 834,230; f90: 235,082; makefile: 79,231; asm: 74,984; xml: 51,692; exp: 39,736; sh: 33,298; objc: 15,629; python: 15,069; fortran: 14,429; pascal: 7,003; awk: 5,070; perl: 3,106; ml: 285; lisp: 253; lex: 204; haskell: 135
file content (237 lines) | stat: -rw-r--r-- 5,103 bytes parent folder | download | duplicates (5)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
//https://issues.dlang.org/show_bug.cgi?id=22291

alias AliasSeq(T...) = T;
void noParameters()
{
    static assert(typeof(__traits(parameters)).length == 0);
}
void noArgs()
{
    //Arguments are not valid, this should not compile
    static assert(!__traits(compiles, __traits(parameters, 456)));
}
shared static this()
{
    static assert(typeof(__traits(parameters)).length == 0);
}
int echoPlusOne(int x)
{
    __traits(parameters)[0] += 1;
    return x;
}
static assert(echoPlusOne(1) == 2);

void nesting(double d, int i)
{
    alias EXP = AliasSeq!(d, i);

    if (d)
    {
        static assert(__traits(isSame, __traits(parameters), EXP));

        while (d)
        {
            static assert(__traits(isSame, __traits(parameters), EXP));
            switch (i)
            {
                static assert(__traits(isSame, __traits(parameters), EXP));
                case 1:
                    static assert(__traits(isSame, __traits(parameters), EXP));
                    break;

                default:
                    static assert(__traits(isSame, __traits(parameters), EXP));
                    break;
            }
        }
    }
}

class Tree {
    int opApply(int delegate(size_t, Tree) dg) {
        if (dg(0, this)) return 1;
        return 0;
    }
}
void useOpApply(Tree top, int x)
{
    foreach(idx; 0..5)
    {
        static assert(is(typeof(__traits(parameters)) == AliasSeq!(Tree, int)));
    }
    foreach(idx, elem; top)
    {
        static assert(is(typeof(__traits(parameters)) == AliasSeq!(Tree, int)));
    }

    foreach(idx, elem; top)
    {
        foreach (idx2, elem2; elem)
            static assert(is(typeof(__traits(parameters)) == AliasSeq!(Tree, int)));
    }

    foreach(idx, elem; top)
    {
        static void foo(char[] text)
        {
            foreach (const char c; text)
                static assert(is(typeof(__traits(parameters)) == AliasSeq!(char[])));
        }
    }
}
class Test
{
    static assert(!__traits(compiles, __traits(parameters)));
    void handle(int x)
    {
        static assert(typeof(__traits(parameters)).length == 1);
    }
}

int add(int x, int y)
{
	return x + y;
}

auto forwardToAdd(int x, int y)
{
	return add(__traits(parameters));
}
static assert(forwardToAdd(2, 3) == 5);
struct TestConstructor
{
    int x;
    string y;
    //This parameter will not have a name but it's (tuple) members
    //will
    this(typeof(this.tupleof))
    {
        this.tupleof = __traits(parameters);
    }
}
bool test(int x, string y)
{
    auto s = TestConstructor(2, "pi");
    return s.x == x && s.y == y;
}
static assert(test(2, "pi"));
int testNested(int x)
{
    static assert(typeof(__traits(parameters)).length == 1);
    int add(int x, int y)
    {
        static assert(typeof(__traits(parameters)).length == 2);
        return x + y;
    }
    return add(x + 2, x + 3);
}
void testPack(Pack...)(Pack x)
{
    static assert(is(typeof(__traits(parameters)) == typeof(AliasSeq!(x))));
}

ref int forwardTest(return ref int x)
{
    static assert(__traits(isRef, x) == __traits(isRef, __traits(parameters)[0]));
    return x;
}

int testRefness(int x, ref int monkey)
{
    {
        //monkey = x;
        __traits(parameters)[1] = __traits(parameters)[0];
    }
    return x;
}
int refTest()
{
    int x;
    testRefness(45, x);
    return x;
}
auto packLength(Pack...)(Pack x)
{
    return typeof(__traits(parameters)).length;
}
static assert(packLength(2, 3) == 2);
alias lambda = (x) => typeof(__traits(parameters)).stringof;
static assert(lambda(1) == "(int)");
static assert(refTest() == 45);

T testTemplate(T)(scope T input)
{
    void chimpInASuit(float set)
    {
        static assert(is(typeof(__traits(parameters)) == AliasSeq!(float)));
    }
    {
        __traits(parameters) = AliasSeq!(T.max);
    }
    __traits(parameters) = AliasSeq!(T.init);
    return input;
}

static assert(testTemplate!long(420) == 0);

void qualifiers(immutable int a, const bool b)
{
    static assert(is(typeof(__traits(parameters)) == AliasSeq!(immutable int, const bool)));
}

int makeAggregate(int a, bool b)
{
    struct S
    {
        typeof(__traits(parameters)) members;
    }

    S s = S(__traits(parameters));
    assert(s.members[0] == a);
    assert(s.members[1] == b);
    return 1;
}

static assert(makeAggregate(5, true));

int makeAlias(int a, bool b)
{
    alias Params = __traits(parameters);
    assert(Params[0] == 3);
    assert(Params[1] == true);
    return 1;
}

static assert(makeAlias(3, true));


mixin template nestedCheckParameters(int unique)
{
    alias NestedNames = __traits(parameters);
    version (Fixed)
    alias Types = typeof(Names);
}

mixin template checkParameters(int unique)
{
    mixin nestedCheckParameters!unique;

    alias Names = __traits(parameters);
    alias Types = typeof(Names);
}

int makeAggregateMixin(immutable int a, const bool b)
{
    mixin checkParameters!0;

    struct S
    {
        mixin checkParameters!1;
        typeof(Names) members;
    }

    S s = S(Names);
    assert(s.members[0] == a);
    assert(s.members[1] == b);
    return 1;
}