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