1 // EXTRA_SOURCES: imports/ufcs5a.d imports/ufcs5b.d imports/ufcs5c.d imports/ufcs5d.d imports/ufcs5e.d
2 
3 module ufcs;
4 
5 extern (C) int printf(const char*, ...);
6 
7 /*******************************************/
8 
9 struct S {}
10 
11 int foo(int n)          { return 1; }
12 int foo(int n, int m)   { return 2; }
13 int goo(int[] a)        { return 1; }
14 int goo(int[] a, int m) { return 2; }
15 int bar(S s)            { return 1; }
16 int bar(S s, int n)     { return 2; }
17 
18 int baz(X)(X x)         { return 1; }
19 int baz(X)(X x, int n)  { return 2; }
20 
21 int temp;
22 ref int boo(int n)      { return temp; }
23 ref int coo(int[] a)    { return temp; }
24 ref int mar(S s)        { return temp; }
25 
26 ref int maz(X)(X x)     { return temp; }
27 
28 void test1()
29 {
30     int n;
31     int[] a;
32     S s;
33 
34     assert(   foo(4)    == 1);      assert(   baz(4)    == 1);
35     assert( 4.foo()     == 1);      assert( 4.baz()     == 1);
36     assert( 4.foo       == 1);      assert( 4.baz       == 1);
37     assert(   foo(4, 2) == 2);      assert(   baz(4, 2) == 2);
38     assert( 4.foo(2)    == 2);      assert( 4.baz(2)    == 2);
39     assert((4.foo = 2)  == 2);      assert((4.baz = 2)  == 2);
40 
41     assert(   goo(a)    == 1);      assert(   baz(a)    == 1);
42     assert( a.goo()     == 1);      assert( a.baz()     == 1);
43     assert( a.goo       == 1);      assert( a.baz       == 1);
44     assert(   goo(a, 2) == 2);      assert(   baz(a, 2) == 2);
45     assert( a.goo(2)    == 2);      assert( a.baz(2)    == 2);
46     assert((a.goo = 2)  == 2);      assert((a.baz = 2)  == 2);
47 
48     assert(   bar(s)    == 1);      assert(   baz(s)    == 1);
49     assert( s.bar()     == 1);      assert( s.baz()     == 1);
50     assert( s.bar       == 1);      assert( s.baz       == 1);
51     assert(   bar(s, 2) == 2);      assert(   baz(s, 2) == 2);
52     assert( s.bar(2)    == 2);      assert( s.baz(2)    == 2);
53     assert((s.bar = 2)  == 2);      assert((s.baz = 2)  == 2);
54 
55     assert((  boo(4) = 2) == 2);    assert((  maz(4) = 2) == 2);
56     assert((4.boo    = 2) == 2);    assert((4.maz    = 2) == 2);
57     assert((  coo(a) = 2) == 2);    assert((  maz(a) = 2) == 2);
58     assert((a.coo    = 2) == 2);    assert((a.maz    = 2) == 2);
59     assert((  mar(s) = 2) == 2);    assert((  maz(s) = 2) == 2);
60     assert((s.mar    = 2) == 2);    assert((s.maz    = 2) == 2);
61 }
62 
63 int hoo(T)(int n)          { return 1; }
64 int hoo(T)(int n, int m)   { return 2; }
65 int koo(T)(int[] a)        { return 1; }
66 int koo(T)(int[] a, int m) { return 2; }
67 int var(T)(S s)            { return 1; }
68 int var(T)(S s, int n)     { return 2; }
69 
70 int vaz(T, X)(X x)         { return 1; }
71 int vaz(T, X)(X x, int n)  { return 2; }
72 
73 //int temp;
74 ref int voo(T)(int n)      { return temp; }
75 ref int woo(T)(int[] a)    { return temp; }
76 ref int nar(T)(S s)        { return temp; }
77 
78 ref int naz(T, X)(X x)     { return temp; }
79 
80 void test2()
81 {
82     int n;
83     int[] a;
84     S s;
85 
86     assert(   hoo!int(4)    == 1);  assert(   vaz!int(4)    == 1);
87     assert( 4.hoo!int()     == 1);  assert( 4.vaz!int()     == 1);
88     assert( 4.hoo!int       == 1);  assert( 4.vaz!int       == 1);
89     assert(   hoo!int(4, 2) == 2);  assert(   vaz!int(4, 2) == 2);
90     assert( 4.hoo!int(2)    == 2);  assert( 4.vaz!int(2)    == 2);
91     assert((4.hoo!int = 2)  == 2);  assert((4.vaz!int = 2)  == 2);
92 
93     assert(   koo!int(a)    == 1);  assert(   vaz!int(a)    == 1);
94     assert( a.koo!int()     == 1);  assert( a.vaz!int()     == 1);
95     assert( a.koo!int       == 1);  assert( a.vaz!int       == 1);
96     assert(   koo!int(a, 2) == 2);  assert(   vaz!int(a, 2) == 2);
97     assert( a.koo!int(2)    == 2);  assert( a.vaz!int(2)    == 2);
98     assert((a.koo!int = 2)  == 2);  assert((a.vaz!int = 2)  == 2);
99 
100     assert(   var!int(s)    == 1);  assert(   vaz!int(s)    == 1);
101     assert( s.var!int()     == 1);  assert( s.vaz!int()     == 1);
102     assert( s.var!int       == 1);  assert( s.vaz!int       == 1);
103     assert(   var!int(s, 2) == 2);  assert(   vaz!int(s, 2) == 2);
104     assert( s.var!int(2)    == 2);  assert( s.vaz!int(2)    == 2);
105     assert((s.var!int = 2)  == 2);  assert((s.vaz!int = 2)  == 2);
106 
107     assert((  voo!int(4) = 2) == 2);    assert((  naz!int(4) = 2) == 2);
108     assert((4.voo!int    = 2) == 2);    assert((4.naz!int    = 2) == 2);
109     assert((  woo!int(a) = 2) == 2);    assert((  naz!int(a) = 2) == 2);
110     assert((a.woo!int    = 2) == 2);    assert((a.naz!int    = 2) == 2);
111     assert((  nar!int(s) = 2) == 2);    assert((  naz!int(s) = 2) == 2);
112     assert((s.nar!int    = 2) == 2);    assert((s.naz!int    = 2) == 2);
113 }
114 
115 /*******************************************/
116 
117 auto init(T)(T val) { return 1; }
118 
119 auto sort(alias fun, T)(T val) { return 1; }
120 
121 @property auto max(alias fun, T)(T val) { return 1; }
122 
123 @property auto infinity(alias opt, T)(T val) { return 1; }
124 
125 void test3()
126 {
127     // See built-in 'init' property
128     assert(1    .init == 0);
129     assert([1]  .init == null);
130     assert([1:1].init == null);
131     assert(1.0  .init is double.nan);
132     assert(10i  .init is idouble.nan);
133     assert('c'  .init == 0xFF);
134     assert("s"  .init == null);
135 
136     // x.init() has parens, so it runs UFCS call
137     assert( 1   .init() == 1);
138     assert([1]  .init() == 1);
139     assert([1:1].init() == 1);
140     assert(1.0  .init() == 1);
141     assert(10i  .init() == 1);
142     assert('c'  .init() == 1);
143     assert("s"  .init() == 1);
144 
145     // x.init!YYY matches templatized UFCS call.
146     assert( 1   .init!int()        == 1);
147     assert([1]  .init!(int[])()    == 1);
148     assert([1:1].init!(int[int])() == 1);
149     assert(1.0  .init!double()     == 1);
150     assert(10i  .init!idouble()    == 1);
151     assert('c'  .init!char()       == 1);
152     assert("s"  .init!string()     == 1);
153 
154     assert([1].sort!"a<b"() == 1);
155     assert([1].sort == [1]);
156 
157     // templatized properties runs UFCS call.
158     assert(1024.max!"a<b" == 1);
159     assert(1024.max  == int.max);
160 
161     assert(3.14.infinity!"+" == 1);
162     assert(3.14.infinity == (double).infinity);
163 }
164 
165 /*******************************************/
166 
167 template Signal4()
168 {
169     void connect(){}
170 }
171 struct S4
172 {
173     mixin Signal4!() s;
174 }
175 void test4()
176 {
177     S4 s;
178     s.s.connect();  // s.s is TOKdotexp, so never match UFCS
179 }
180 
181 /*******************************************/
182 
183 auto f5_1(int)    { return 1; }
184 auto f5_2(string) { return 2; }
185 auto f5_3(double) { return 3; }
186 alias f5_4 = f5_1, f5_4 = f5_2;
187 alias f5_5 = f5_3, f5_5 = f5_4;
188 
189 @property p5_1(int)    { return 1; }    @property p5_1(int,    int) { return 1; }
190 @property p5_2(string) { return 2; }    @property p5_2(string, int) { return 2; }
191 @property p5_3(double) { return 3; }    @property p5_3(double, int) { return 3; }
192 alias p5_4 = p5_1, p5_4 = p5_2;         alias p5_4 = p5_1, p5_4 = p5_2;
193 alias p5_5 = p5_3, p5_5 = p5_4;         alias p5_5 = p5_3, p5_5 = p5_4;
194 
195 // import overload set 'f5ov' and 'p5ov'
196 import imports.ufcs5b, imports.ufcs5c;
197 
198 void test5()
199 {
200     {
201         // f5_1 .. f5_5 are symbols which declared in module scope
202         assert(100.f5_1() == 1);
203         assert("s".f5_2() == 2);
204         assert(1.4.f5_3() == 3);
205         assert(100.f5_4() == 1);
206         assert("s".f5_4() == 2);
207         assert(100.f5_5() == 1);
208         assert("s".f5_5() == 2);
209         assert(1.4.f5_5() == 3);
210         // overload set
211         assert(100.f5ov() == 1);
212         assert("s".f5ov() == 2);
213         // UFCS does not see function local alias
214         alias func5 = f5_1;
215         static assert(!__traits(compiles, { 1.func5(); }));
216 
217         // property getter/setter
218         assert(100.p5_1 == 1);      assert((100.p5_1 = 1) == 1);
219         assert("s".p5_2 == 2);      assert(("s".p5_2 = 1) == 2);
220         assert(1.4.p5_3 == 3);      assert((1.4.p5_3 = 1) == 3);
221         assert(100.p5_4 == 1);      assert((100.p5_4 = 1) == 1);
222         assert("s".p5_4 == 2);      assert(("s".p5_4 = 1) == 2);
223         assert(100.p5_5 == 1);      assert((100.p5_5 = 1) == 1);
224         assert("s".p5_5 == 2);      assert(("s".p5_5 = 1) == 2);
225         assert(1.4.p5_5 == 3);      assert((1.4.p5_5 = 1) == 3);
226         // overload set     );      assert(
227         assert(100.p5ov == 1);      assert((100.p5ov = 1) == 1);
228         assert("s".p5ov == 2);      assert(("s".p5ov = 1) == 2);
229         // local alias
230         alias prop5 = p5_1;
231         static assert(!__traits(compiles, { 1.prop5; }));
232         static assert(!__traits(compiles, { 1.prop5 = 1; }));
233     }
234 
235     {
236         // f5a1 .. f5a5 are symbols which declared in module scope
237         import imports.ufcs5a;
238         // overload set 'f5ov' and 'p5ov'
239         import imports.ufcs5b, imports.ufcs5c;
240 
241         assert(100.f5a1() == 1);
242         assert("s".f5a2() == 2);
243         assert(1.4.f5a3() == 3);
244         assert(100.f5a4() == 1);
245         assert("s".f5a4() == 2);
246         assert(100.f5a5() == 1);
247         assert("s".f5a5() == 2);
248         assert(1.4.f5a5() == 3);
249         assert(100.f5ov() == 1);
250         assert("s".f5ov() == 2);
251 
252         assert(100.p5a1 == 1);      assert((100.p5a1 = 1) == 1);
253         assert("s".p5a2 == 2);      assert(("s".p5a2 = 1) == 2);
254         assert(1.4.p5a3 == 3);      assert((1.4.p5a3 = 1) == 3);
255         assert(100.p5a4 == 1);      assert((100.p5a4 = 1) == 1);
256         assert("s".p5a4 == 2);      assert(("s".p5a4 = 1) == 2);
257         assert(100.p5a5 == 1);      assert((100.p5a5 = 1) == 1);
258         assert("s".p5a5 == 2);      assert(("s".p5a5 = 1) == 2);
259         assert(1.4.p5a5 == 3);      assert((1.4.p5a5 = 1) == 3);
260         assert(100.p5ov == 1);      assert((100.p5ov = 1) == 1);
261         assert("s".p5ov == 2);      assert(("s".p5ov = 1) == 2);
262     }
263 
264     {
265         // selective imports also work as expected
266         import imports.ufcs5a : f5a1, f5a2;
267         import imports.ufcs5a : p5a1, p5a2;
268 
269         assert(100.f5a1() == 1);
270         assert("s".f5a2() == 2);
271         static assert(!__traits(compiles, { 1.4.f5a3(); }));
272         static assert(!__traits(compiles, { 100.f5a4(); }));
273         static assert(!__traits(compiles, { "s".f5a4(); }));
274         static assert(!__traits(compiles, { 100.f5a5(); }));
275         static assert(!__traits(compiles, { "s".f5a5(); }));
276         static assert(!__traits(compiles, { 1.4.f5a5(); }));
277 
278         assert(100.p5a1 == 1);      assert((100.p5a1 = 1) == 1);
279         assert("s".p5a2 == 2);      assert(("s".p5a2 = 1) == 2);
280         static assert(!__traits(compiles, { 1.4.p5a3; }) && !__traits(compiles, { 1.4.p5a3 = 1; }));
281         static assert(!__traits(compiles, { 100.p5a4; }) && !__traits(compiles, { 100.p5a4 = 1; }));
282         static assert(!__traits(compiles, { "s".p5a4; }) && !__traits(compiles, { "s".p5a4 = 1; }));
283         static assert(!__traits(compiles, { 100.p5a5; }) && !__traits(compiles, { 100.p5a5 = 1; }));
284         static assert(!__traits(compiles, { "s".p5a5; }) && !__traits(compiles, { "s".p5a5 = 1; }));
285         static assert(!__traits(compiles, { 1.4.p5a5; }) && !__traits(compiles, { 1.4.p5a5 = 1; }));
286     }
287 
288     {
289         // renamed imports also work as expected
290         import imports.ufcs5a : f5x1 = f5a1, f5x2 = f5a2;
291         import imports.ufcs5a : p5x1 = p5a1, p5x2 = p5a2;
292 
293         assert(100.f5x1() == 1);
294         assert("s".f5x2() == 2);
295         static assert(!__traits(compiles, { 100.f5a1(); }));
296         static assert(!__traits(compiles, { "s".f5a2(); }));
297         static assert(!__traits(compiles, { 1.4.f5a3(); }));
298         static assert(!__traits(compiles, { 100.f5a4(); }));
299         static assert(!__traits(compiles, { "s".f5a4(); }));
300         static assert(!__traits(compiles, { 100.f5a5(); }));
301         static assert(!__traits(compiles, { "s".f5a5(); }));
302         static assert(!__traits(compiles, { 1.4.f5a5(); }));
303 
304         assert(100.p5x1 == 1);      assert((100.p5x1 = 1) == 1);
305         assert("s".p5x2 == 2);      assert(("s".p5x2 = 1) == 2);
306         static assert(!__traits(compiles, { 100.p5a1; }) && !__traits(compiles, { 100.p5a1 = 1; }));
307         static assert(!__traits(compiles, { "s".p5a2; }) && !__traits(compiles, { "s".p5a2 = 1; }));
308         static assert(!__traits(compiles, { 1.4.p5a3; }) && !__traits(compiles, { 1.4.p5a3 = 1; }));
309         static assert(!__traits(compiles, { 100.p5a4; }) && !__traits(compiles, { 100.p5a4 = 1; }));
310         static assert(!__traits(compiles, { "s".p5a4; }) && !__traits(compiles, { "s".p5a4 = 1; }));
311         static assert(!__traits(compiles, { 100.p5a5; }) && !__traits(compiles, { 100.p5a5 = 1; }));
312         static assert(!__traits(compiles, { "s".p5a5; }) && !__traits(compiles, { "s".p5a5 = 1; }));
313         static assert(!__traits(compiles, { 1.4.p5a5; }) && !__traits(compiles, { 1.4.p5a5 = 1; }));
314     }
315 
316     {
317         auto c5 = new C5();
318         foreach (name; __traits(allMembers, C5))
319         {
320             static if (name.length >= 4 && name[0..4] == "test")
321             {
322                 mixin("c5."~name~"();");    // call test function
323             }
324         }
325     }
326 }
327 
328 class B5
329 {
330     int g5bm(int) { return 0; }
331     static int g5bs(int) { return 0; }
332 
333 }
334 class C5 : B5
335 {
336     // normal import works.
337     import imports.ufcs5a;
338     void test1()
339     {
340         assert(100.f5a1() == 1);
341         assert("s".f5a2() == 2);
342         assert(1.4.f5a3() == 3);
343         assert(100.f5a4() == 1);
344         assert("s".f5a4() == 2);
345         assert(100.f5a5() == 1);
346         assert("s".f5a5() == 2);
347         assert(1.4.f5a5() == 3);
348 
349         assert(100.p5a1 == 1);      assert((100.p5a1 = 1) == 1);
350         assert("s".p5a2 == 2);      assert(("s".p5a2 = 1) == 2);
351         assert(1.4.p5a3 == 3);      assert((1.4.p5a3 = 1) == 3);
352         assert(100.p5a4 == 1);      assert((100.p5a4 = 1) == 1);
353         assert("s".p5a4 == 2);      assert(("s".p5a4 = 1) == 2);
354         assert(100.p5a5 == 1);      assert((100.p5a5 = 1) == 1);
355         assert("s".p5a5 == 2);      assert(("s".p5a5 = 1) == 2);
356         assert(1.4.p5a5 == 3);      assert((1.4.p5a5 = 1) == 3);
357     }
358 
359     // selective imports also work as expected
360     import imports.ufcs5d : f5d1, f5d2;
361     import imports.ufcs5d : p5d1, p5d2;
362     void test2()
363     {
364         assert(100.f5d1() == 1);
365         assert("s".f5d2() == 2);
366         static assert(!__traits(compiles, { 1.4.f5d3(); }));
367         static assert(!__traits(compiles, { 100.f5d4(); }));
368         static assert(!__traits(compiles, { "s".f5d4(); }));
369         static assert(!__traits(compiles, { 100.f5d5(); }));
370         static assert(!__traits(compiles, { "s".f5d5(); }));
371         static assert(!__traits(compiles, { 1.4.f5d5(); }));
372 
373         assert(100.p5d1 == 1);  assert((100.p5d1 = 1) == 1);
374         assert("s".p5d2 == 2);  assert(("s".p5d2 = 1) == 2);
375         static assert(!__traits(compiles, { 1.4.p5d3; }) && !__traits(compiles, { 1.4.p5d3 = 1; }));
376         static assert(!__traits(compiles, { 100.p5d4; }) && !__traits(compiles, { 100.p5d4 = 1; }));
377         static assert(!__traits(compiles, { "s".p5d4; }) && !__traits(compiles, { "s".p5d4 = 1; }));
378         static assert(!__traits(compiles, { 100.p5d5; }) && !__traits(compiles, { 100.p5d5 = 1; }));
379         static assert(!__traits(compiles, { "s".p5d5; }) && !__traits(compiles, { "s".p5d5 = 1; }));
380         static assert(!__traits(compiles, { 1.4.p5d5; }) && !__traits(compiles, { 1.4.p5d5 = 1; }));
381     }
382 
383     // renamed imports also work as expected
384     import imports.ufcs5e : f5y1 = f5e1, f5y2 = f5e2;
385     import imports.ufcs5e : p5y1 = p5e1, p5y2 = p5e2;
386     void test3()
387     {
388         assert(100.f5y1() == 1);
389         assert("s".f5y2() == 2);
390         static assert(!__traits(compiles, { 100.f5e1(); }));
391         static assert(!__traits(compiles, { "s".f5e2(); }));
392         static assert(!__traits(compiles, { 1.4.f5e3(); }));
393         static assert(!__traits(compiles, { 100.f5e4(); }));
394         static assert(!__traits(compiles, { "s".f5e4(); }));
395         static assert(!__traits(compiles, { 100.f5e5(); }));
396         static assert(!__traits(compiles, { "s".f5e5(); }));
397         static assert(!__traits(compiles, { 1.4.f5e5(); }));
398 
399         assert(100.p5y1 == 1);  assert((100.p5y1 = 1) == 1);
400         assert("s".p5y2 == 2);  assert(("s".p5y2 = 1) == 2);
401         static assert(!__traits(compiles, { 100.p5e1; }) && !__traits(compiles, { (100.p5e1 = 1); }));
402         static assert(!__traits(compiles, { "s".p5e2; }) && !__traits(compiles, { ("s".p5e2 = 1); }));
403         static assert(!__traits(compiles, { 1.4.p5e3; }) && !__traits(compiles, { (1.4.p5e3 = 1); }));
404         static assert(!__traits(compiles, { 100.p5e4; }) && !__traits(compiles, { (100.p5e4 = 1); }));
405         static assert(!__traits(compiles, { "s".p5e4; }) && !__traits(compiles, { ("s".p5e4 = 1); }));
406         static assert(!__traits(compiles, { 100.p5e5; }) && !__traits(compiles, { (100.p5e5 = 1); }));
407         static assert(!__traits(compiles, { "s".p5e5; }) && !__traits(compiles, { ("s".p5e5 = 1); }));
408         static assert(!__traits(compiles, { 1.4.p5e5; }) && !__traits(compiles, { (1.4.p5e5 = 1); }));
409     }
410 
411     int g5cm(int) { return 0; }
412     static int g5cs(int) { return 0; }
413     void test4()
414     {
415         // UFCS does not see aggregate members
416         static assert(!__traits(compiles, { 1.g5cm(); }));
417         static assert(!__traits(compiles, { 1.g5cs(); }));
418 
419         // Even if it is in base class
420         static assert(!__traits(compiles, { 1.g5bm(); }));
421         static assert(!__traits(compiles, { 1.g5bs(); }));
422     }
423 }
424 
425 /*******************************************/
426 // 662
427 
428 import std.stdio,std..string, std.conv;
429 
430 enum Etest
431 {
432     a,b,c,d
433 }
434 
435 //typedef int testi = 10;
436 //typedef Test Test2;
437 
438 int test() { return 33; }
439 
440 class Test
441 {
442     static int test(int i) { return i; }
443 }
444 
445 int test(Etest test)
446 {
447     return cast(int)test;
448 }
449 
450 //int test(testi i)
451 //{
452 //  return cast(int)i;
453 //}
454 
455 void test682()
456 {
457     assert(22.to!string() == "22");
458     assert((new Test).test(11) == 11);
459     assert(Test.test(11) == 11);
460     //assert(Test2.test(11) == 11);
461     assert(test() == 33);
462     assert(ufcs.test() == 33);
463     assert(Etest.d.test() == Etest.d);
464     //testi i;
465     //assert(i.test() == i.init);
466 }
467 
468 /*******************************************/
469 // 3382
470 
471 import std.range, std.algorithm;
472 
473 @property T twice(T)(T x){ return x * x; }
474 real toreal(ireal x){ return x.im; }
475 char toupper(char c){ return ('a'<=c && c<='z') ? cast(char)(c - 'a' + 'A') : c; }
476 
477 @property ref T setter(T)(ref T x, T v){ x = v; return x; }
478 
479 void test3382()
480 {
481     auto r = iota(0, 10).map!"a*3"().filter!"a%2 != 0"();
482     foreach (e; r)
483         printf("e = %d\n", e);
484 
485     assert(10.twice == 100);
486     assert(0.5.twice == 0.25);
487     assert(1.4i.toreal() == 1.4);
488     assert('c'.toupper() == 'C');
489 }
490 
491 /*******************************************/
492 // 6185
493 
494 void test6185()
495 {
496     import std.algorithm;
497 
498     auto r1 = [1,2,3].map!"a*2";
499     assert(equal(r1, [2,4,6]));
500 
501     auto r2 = r1.map!"a+2"();
502     assert(equal(r2, [4,6,8]));
503 }
504 
505 /*******************************************/
506 // 6070
507 
508 enum test6070a = ["test"].foo6070();
509 enum test6070b = foo6070(["test"]);
510 
511 string foo6070(string[] s) { return ""; }
512 
513 /*******************************************/
514 // 7670
515 
516 struct A7670
517 {
518     double x;
519 }
520 @property ref double y7670(ref A7670 a)
521 {
522     return a.x;
523 }
524 void test7670()
525 {
526     A7670 a1;
527     a1.y7670() = 2.0; // OK
528     a1.y7670 = 2.0; // Error
529 }
530 
531 /*******************************************/
532 // 7703
533 void f7703(T)(T a) { }
534 
535 void test7703()
536 {
537     int x;
538     x.f7703;        // accepted
539     x.f7703();      // accepted
540     x.f7703!int;    // rejected -- "f(x) isn't a template"
541     x.f7703!int();  // accepted
542 }
543 
544 /*******************************************/
545 // 7773
546 
547 //import std.stdio;
548 void writeln7773(int n){}
549 void test7773()
550 {
551     (int.max).writeln7773(); // OK
552     int.max.writeln7773();   // error
553 }
554 
555 /*******************************************/
556 // 7943
557 
558 struct Foo7943
559 {
560     int _member;
561     alias _member this;
562 }
563 
564 int foo7943(Foo7943 f) { return 1; }
565 int foo7943(int i) { return 2; }
566 
567 void test7943()
568 {
569     Foo7943 f;
570     assert(f.foo7943() == 1);
571 }
572 
573 /*******************************************/
574 // 8180
575 
576 int writeln8180(T...)(T args) { return 1; }
577 
578 struct Tuple8180(T...)
579 {
580     T field;
581     alias field this;
582 }
583 
584 void test8180()
585 {
586     auto t = Tuple8180!(int)(10);
587     assert(t.writeln8180() == 1);
588 }
589 
590 /*******************************************/
591 // 8245
592 
593           string toStr8245(immutable(char)* p) { return null; }
594 @property string asStr8245(immutable(char)* p) { return null; }
595 
596 void test8245()
597 {
598     immutable(char)* p = "foobar".ptr;
599     p.toStr8245();
600     p.asStr8245;    // Error: no property 'asStr' for type 'immutable(char)'
601 }
602 
603 /*******************************************/
604 // 8252
605 
606 bool f(int x) { return !x; }
607 
608 void test8252()
609 {
610     static assert(!1.f); // ok
611     static assert( 0.f); // fail
612 }
613 
614 /*******************************************/
615 // 8453
616 
617 T[] sort8453(T)(T[] a) { return a; }
618 
619 void test8453()
620 {
621     int[int] foo;
622     auto bar1 = foo.keys().sort8453(); // OK
623     auto bar2 = foo.keys.sort8453();   // Error
624 }
625 
626 /*******************************************/
627 // 8503
628 
629 void α8503(int i) {}
630 
631 void test8503()
632 {
633     0.α8503();  // Error
634     1.α8503();  // Error
635 }
636 
637 /*******************************************/
638 // 9014
639 
640 @property ref int foo9014(int[] a)
641 {
642     return a[0];
643 }
644 void test9014()
645 {
646     int[] bar;
647   static assert(!__traits(compiles, {
648     bar.foo9014 = missing.foo9014;
649   }));
650 }
651 
652 /*******************************************/
653 // 9590
654 
655 auto func9590(E)(lazy E expr) { }
656 
657 int f9590a()  { assert(0); }
658 void f9590b() { assert(0); }
659 
660 void test9590()
661 {
662     func9590(f9590a());  // ok, no exceptions (lazy)
663     f9590a().func9590;   // ok, no exceptions (lazy)
664 
665     func9590(f9590b());  // ok, no exceptions (lazy)
666     f9590b().func9590;   // L12: NG
667 }
668 
669 /*******************************************/
670 // 9946
671 
672 size_t count9946(alias x)(int[] haystack)
673 {
674     return 0;
675 }
676 void test9946()
677 {
678     int[] data;
679     auto n1 = count9946!5(data);          // OK
680     auto n2 = data.count9946!5;           // OK
681     auto a1 = new int[count9946!5(data)]; // OK
682     auto a2 = new int[data.count9946!5];  // Error
683 }
684 
685 /*******************************************/
686 // 10618
687 
688 template Temp10618(T)
689 {
690     size_t len = 1;
691 }
692 void test10618()
693 {
694     auto arr = new int[Temp10618!int.len];
695     assert(arr.length == 1);
696 }
697 
698 /*******************************************/
699 // 10003
700 
701 void foo10003(void *p) {}
702 void test10003()
703 {
704     void* p;
705     p.foo10003();
706 }
707 
708 /*******************************************/
709 // 10041
710 
711 auto writeln10041(T...)(T args) { return typeof(args[0]).stringof; }
712 
713 void test10041()
714 {
715     auto aa = [1: 2];
716     assert(aa.writeln10041 == "int[int]");
717     assert(writeln10041(aa) == "int[int]");
718 }
719 
720 /*******************************************/
721 // 10047
722 
723 struct Typedef10047(T)
724 {
725     template opDispatch(string name)
726     {
727         static assert(0);
728     }
729 }
730 
731 struct A10047 {}
732 int foo10047(Typedef10047!A10047 a) { return 10; }
733 
734 void test10047()
735 {
736     Typedef10047!A10047 a;
737     assert(a.foo10047() == 10);
738 }
739 
740 /*******************************************/
741 // 10166
742 
743 auto foo10166()
744 {
745     0.bar10166!({})(0);
746 }
747 
748 void bar10166(alias handler, T)(T t, int i)
749 {
750     t.bar10166!buzz10166(i);
751 }
752 
753 void buzz10166() {}
754 
755 /*******************************************/
756 // 10526
757 
758 struct S10526
759 {
760     int opDispatch(string s, A...)(A args)
761     if (s[0..3] == "foo")
762     {
763         return 1;
764     }
765 }
766 int bar10526(X)(X) { return 2; }
767 int baz10526(T, X)(X) { return 3; }
768 
769 void test10526()
770 {
771     S10526 s;
772 
773     // with parenthesis
774     assert(s.foo10526() == 1);
775     assert(s.bar10526() == 2);
776     assert(s.baz10526!string() == 3);
777 
778     // without parenthesis
779     assert(s.foo10526 == 1);
780     assert(s.bar10526 == 2);
781     assert(s.baz10526!string == 3);
782 }
783 
784 /********************************************************/
785 // 10609
786 
787 int foo10609(int x) { return x; }
788 
789 void test10609()
790 {
791     int x = 1;
792     static assert(__traits(compiles, foo10609(x)));
793     static assert(__traits(compiles, 1.foo10609 ));
794     static assert(__traits(compiles, x.foo10609 ));
795 }
796 
797 /*******************************************/
798 // 11312
799 
800 struct S11312;
801 
802 S11312* getS11312() { return null; }
803 int getValue(S11312*) { return 10; }
804 
805 void test11312()
806 {
807     S11312* op = getS11312();
808     int x = op.getValue();
809     assert(x == 10);
810 }
811 
812 /*******************************************/
813 // 15123
814 
815 auto keys15123(K, V)(V[K] aa) { return [1]; }
816 auto values15123(K, V)(V[K] aa) { return [2]; }
817 
818 alias id15123(alias arg) = arg;
819 
820 enum int[int] aa15123 = [1:2];
821 static assert(id15123!(aa15123.keys15123) == [1]);  // TypeIdentifier + UFCS
822 
823 T[T] f15123(T)() { return [1:2]; }
824 static assert(id15123!(f15123!int.values15123) == [2]); // TypeInstance + UFCS
825 
826 /*******************************************/
827 
828 int main()
829 {
830     test1();
831     test2();
832     test3();
833     test4();
834     test5();
835     test682();
836     test3382();
837     test6185();
838     test7670();
839     test7703();
840     test7773();
841     test7943();
842     test8180();
843     test8245();
844     test8252();
845     test8453();
846     test8503();
847     test9014();
848     test9590();
849     test9946();
850     test10618();
851     test10003();
852     test10041();
853     test10047();
854     test10526();
855     test11312();
856 
857     printf("Success\n");
858     return 0;
859 }