/
funclit.d
895 lines (739 loc) · 22.6 KB
/
funclit.d
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
import core.vararg;
extern (C) int printf(const char*, ...);
/***************************************************/
// lambda syntax check
auto una(alias dg)(int n)
{
return dg(n);
}
auto bin(alias dg)(int n, int m)
{
return dg(n, m);
}
void test1()
{
assert(una!( a => a*2 )(2) == 4);
assert(una!( ( a) => a*2 )(2) == 4);
assert(una!( (int a) => a*2 )(2) == 4);
assert(una!( ( a){ return a*2; } )(2) == 4);
assert(una!( function ( a){ return a*2; } )(2) == 4);
assert(una!( function int( a){ return a*2; } )(2) == 4);
assert(una!( function (int a){ return a*2; } )(2) == 4);
assert(una!( function int(int a){ return a*2; } )(2) == 4);
assert(una!( delegate ( a){ return a*2; } )(2) == 4);
assert(una!( delegate int( a){ return a*2; } )(2) == 4);
assert(una!( delegate (int a){ return a*2; } )(2) == 4);
assert(una!( delegate int(int a){ return a*2; } )(2) == 4);
// partial parameter specialization syntax
assert(bin!( ( a, b) => a*2+b )(2,1) == 5);
assert(bin!( (int a, b) => a*2+b )(2,1) == 5);
assert(bin!( ( a, int b) => a*2+b )(2,1) == 5);
assert(bin!( (int a, int b) => a*2+b )(2,1) == 5);
assert(bin!( ( a, b){ return a*2+b; } )(2,1) == 5);
assert(bin!( (int a, b){ return a*2+b; } )(2,1) == 5);
assert(bin!( ( a, int b){ return a*2+b; } )(2,1) == 5);
assert(bin!( (int a, int b){ return a*2+b; } )(2,1) == 5);
assert(bin!( function ( a, b){ return a*2+b; } )(2,1) == 5);
assert(bin!( function (int a, b){ return a*2+b; } )(2,1) == 5);
assert(bin!( function ( a, int b){ return a*2+b; } )(2,1) == 5);
assert(bin!( function (int a, int b){ return a*2+b; } )(2,1) == 5);
assert(bin!( function int( a, b){ return a*2+b; } )(2,1) == 5);
assert(bin!( function int(int a, b){ return a*2+b; } )(2,1) == 5);
assert(bin!( function int( a, int b){ return a*2+b; } )(2,1) == 5);
assert(bin!( function int(int a, int b){ return a*2+b; } )(2,1) == 5);
assert(bin!( delegate ( a, b){ return a*2+b; } )(2,1) == 5);
assert(bin!( delegate (int a, b){ return a*2+b; } )(2,1) == 5);
assert(bin!( delegate ( a, int b){ return a*2+b; } )(2,1) == 5);
assert(bin!( delegate (int a, int b){ return a*2+b; } )(2,1) == 5);
assert(bin!( delegate int( a, b){ return a*2+b; } )(2,1) == 5);
assert(bin!( delegate int(int a, b){ return a*2+b; } )(2,1) == 5);
assert(bin!( delegate int( a, int b){ return a*2+b; } )(2,1) == 5);
assert(bin!( delegate int(int a, int b){ return a*2+b; } )(2,1) == 5);
}
/***************************************************/
// on initializer
void test2()
{
// explicit typed binding ignite parameter types inference
int function(int) fn1 = a => a*2; assert(fn1(2) == 4);
int function(int) fn2 = ( a){ return a*2; }; assert(fn2(2) == 4);
int function(int) fn3 = function ( a){ return a*2; }; assert(fn3(2) == 4);
int function(int) fn4 = function int( a){ return a*2; }; assert(fn4(2) == 4);
int function(int) fn5 = function (int a){ return a*2; }; assert(fn5(2) == 4);
int function(int) fn6 = function int(int a){ return a*2; }; assert(fn6(2) == 4);
int delegate(int) dg1 = a => a*2; assert(dg1(2) == 4);
int delegate(int) dg2 = ( a){ return a*2; }; assert(dg2(2) == 4);
int delegate(int) dg3 = delegate ( a){ return a*2; }; assert(dg3(2) == 4);
int delegate(int) dg4 = delegate int( a){ return a*2; }; assert(dg4(2) == 4);
int delegate(int) dg5 = delegate (int a){ return a*2; }; assert(dg5(2) == 4);
int delegate(int) dg6 = delegate int(int a){ return a*2; }; assert(dg6(2) == 4);
// funciton/delegate mismatching always raises an error
static assert(!__traits(compiles, { int function(int) xfg3 = delegate ( a){ return a*2; }; }));
static assert(!__traits(compiles, { int function(int) xfg4 = delegate int( a){ return a*2; }; }));
static assert(!__traits(compiles, { int function(int) xfg5 = delegate (int a){ return a*2; }; }));
static assert(!__traits(compiles, { int function(int) xfg6 = delegate int(int a){ return a*2; }; }));
static assert(!__traits(compiles, { int delegate(int) xdn3 = function ( a){ return a*2; }; }));
static assert(!__traits(compiles, { int delegate(int) xdn4 = function int( a){ return a*2; }; }));
static assert(!__traits(compiles, { int delegate(int) xdn5 = function (int a){ return a*2; }; }));
static assert(!__traits(compiles, { int delegate(int) xdn6 = function int(int a){ return a*2; }; }));
// auto binding requires explicit parameter types at least
static assert(!__traits(compiles, { auto afn1 = a => a*2; }));
static assert(!__traits(compiles, { auto afn2 = ( a){ return a*2; }; }));
static assert(!__traits(compiles, { auto afn3 = function ( a){ return a*2; }; }));
static assert(!__traits(compiles, { auto afn4 = function int( a){ return a*2; }; }));
static assert(!__traits(compiles, { auto adg3 = delegate ( a){ return a*2; }; }));
static assert(!__traits(compiles, { auto adg4 = delegate int( a){ return a*2; }; }));
auto afn5 = function (int a){ return a*2; }; assert(afn5(2) == 4);
auto afn6 = function int(int a){ return a*2; }; assert(afn6(2) == 4);
auto adg5 = delegate (int a){ return a*2; }; assert(adg5(2) == 4);
auto adg6 = delegate int(int a){ return a*2; }; assert(adg6(2) == 4);
// partial specialized lambda
string delegate(int, string) dg =
(n, string s){
string r = "";
foreach (_; 0..n) r~=s;
return r;
};
assert(dg(2, "str") == "strstr");
}
/***************************************************/
// on return statement
void test3()
{
// inference matching system is same as on initializer
int delegate(int) mul(int x)
{
return a => a * x;
}
assert(mul(5)(2) == 10);
}
/***************************************************/
// on function arguments
auto foo4(int delegate(int) dg) { return dg(10); }
auto foo4(int delegate(int, int) dg) { return dg(10, 20); }
void nbar4fp(void function(int) fp) { }
void nbar4dg(void delegate(int) dg) { }
void tbar4fp(T,R)(R function(T) dg) { static assert(is(typeof(dg) == void function(int))); }
void tbar4dg(T,R)(R delegate(T) dg) { static assert(is(typeof(dg) == void delegate(int))); }
auto nbaz4(void function() fp) { return 1; }
auto nbaz4(void delegate() dg) { return 2; }
auto tbaz4(R)(R function() dg) { static assert(is(R == void)); return 1; }
auto tbaz4(R)(R delegate() dg) { static assert(is(R == void)); return 2; }
auto thoo4(T)(T lambda){ return lambda; }
void tfun4a()(int function(int) a){}
void tfun4b(T)(T function(T) a){}
void tfun4c(T)(T f){}
void test4()
{
int v;
static void sfoo() {}
void nfoo() {}
// parameter type inference + overload resolution
assert(foo4((a) => a * 2) == 20);
assert(foo4((a,b) => a * 2 + b) == 40);
// function/delegate inference
nbar4fp((int x){ });
nbar4dg((int x){ });
tbar4fp((int x){ });
tbar4dg((int x){ });
// function/delegate inference + overload resolution
assert(nbaz4({ }) == 1);
assert(nbaz4({ v = 1; }) == 2);
assert(nbaz4({ sfoo(); }) == 1); // Bugzilla 8836
assert(nbaz4({ nfoo(); }) == 2);
assert(tbaz4({ }) == 1);
assert(tbaz4({ v = 1; }) == 2);
assert(tbaz4({ sfoo(); }) == 1);
assert(tbaz4({ nfoo(); }) == 2);
// template function deduction
static assert(is(typeof(thoo4({ })) : void function()));
static assert(is(typeof(thoo4({ v = 1; })) : void delegate()));
tfun4a(a => a);
static assert(!__traits(compiles, { tfun4b(a => a); }));
static assert(!__traits(compiles, { tfun4c(a => a); }));
}
void fsvarg4(int function(int)[] a...){}
void fcvarg4(int dummy, ...){}
void tsvarg4a()(int function(int)[] a...){}
void tsvarg4b(T)(T function(T)[] a...){}
void tsvarg4c(T)(T [] a...){}
void tcvarg4()(int dummy, ...){}
void test4v()
{
fsvarg4(function(int a){ return a; }); // OK
fsvarg4(a => a); // OK
fcvarg4(0, function(int a){ return a; }); // OK
static assert(!__traits(compiles, { fcvarg4(0, a => a); }));
tsvarg4a(function(int a){ return a; }); // OK
tsvarg4b(function(int a){ return a; }); // OK
tsvarg4c(function(int a){ return a; }); // OK
tsvarg4a(a => a);
static assert(!__traits(compiles, { tsvarg4b(a => a); }));
static assert(!__traits(compiles, { tsvarg4c(a => a); }));
tcvarg4(0, function(int a){ return a; }); // OK
static assert(!__traits(compiles, { tcvarg4(0, a => a); }));
}
/***************************************************/
// on CallExp::e1
void test5()
{
assert((a => a*2)(10) == 20);
assert(( a, s){ return s~s; }(10, "str") == "strstr");
assert((int a, s){ return s~s; }(10, "str") == "strstr");
assert(( a, string s){ return s~s; }(10, "str") == "strstr");
assert((int a, string s){ return s~s; }(10, "str") == "strstr");
}
/***************************************************/
// escape check to nested function symbols
void checkNestedRef(alias dg)(bool isnested)
{
static if (is(typeof(dg) == delegate))
enum isNested = true;
else static if ((is(typeof(dg) PF == F*, F) && is(F == function)))
enum isNested = false;
else
static assert(0);
assert(isnested == isNested);
dg();
}
void freeFunc(){}
void test6()
{
static void localFunc(){}
void nestedLocalFunc(){}
checkNestedRef!({ })(false);
checkNestedRef!({ freeFunc(); })(false);
checkNestedRef!({ localFunc(); })(false);
checkNestedRef!({ nestedLocalFunc(); })(true);
checkNestedRef!({ void inner(){} inner(); })(false);
checkNestedRef!({ auto f = &freeFunc; })(false);
checkNestedRef!({ auto f = &localFunc; })(false);
checkNestedRef!({ auto f = &nestedLocalFunc; })(true);
checkNestedRef!({ void inner(){} auto f = &inner; })(false);
}
/***************************************************/
// on AssignExp::e2
void test7()
{
int function(int) fp;
fp = a => a;
fp = (int a) => a;
fp = function(int a) => a;
fp = function int(int a) => a;
static assert(!__traits(compiles, { fp = delegate(int a) => a; }));
static assert(!__traits(compiles, { fp = delegate int(int a) => a; }));
int delegate(int) dg;
dg = a => a;
dg = (int a) => a;
dg = delegate(int a) => a;
dg = delegate int(int a) => a;
static assert(!__traits(compiles, { dg = function(int a) => a; }));
static assert(!__traits(compiles, { dg = function int(int a) => a; }));
}
/***************************************************/
// on StructLiteralExp::elements
void test8()
{
struct S
{
int function(int) fp;
}
auto s1 = S(a => a);
static assert(!__traits(compiles, { auto s2 = S((a, b) => a); }));
}
/***************************************************/
// on concat operation
void test9()
{
int function(int)[] a2;
a2 ~= x => x;
}
/***************************************************/
// on associative array key
void test10()
{
int[int function()] aa;
assert(!aa.remove(() => 1));
int[int function(int)] aa2;
assert(!aa2.remove(x => 1));
}
/***************************************************/
// on common type deduction
void test11()
{
auto a1 = [x => x, (int x) => x * 2];
static assert(is(typeof(a1[0]) == int function(int) pure @safe nothrow));
assert(a1[0](10) == 10);
assert(a1[1](10) == 20);
//int n = 10;
//auto a2 = [x => n, (int x) => x * 2];
//static assert(is(typeof(a2[0]) == int delegate(int) @safe nothrow));
//assert(a2[0](99) == 10);
//assert(a2[1](10) == 20);
int function(int) fp = true ? (x => x) : (x => x*2);
assert(fp(10) == 10);
int m = 10;
int delegate(int) dg = true ? (x => x) : (x => m*2);
assert(dg(10) == 10);
}
/***************************************************/
// 3235
void test3235()
{
// from TDPL
auto f = (int i) {};
static if (is(typeof(f) _ == F*, F) && is(F == function))
{} else static assert(0);
}
/***************************************************/
// 6714
void foo6714x(int function (int, int) a){}
void bar6714x(int delegate (int, int) a){}
int bar6714y(double delegate(int, int) a){ return 1; }
int bar6714y( int delegate(int, int) a){ return 2; }
void test6714()
{
foo6714x((a, b) { return a + b; });
bar6714x((a, b) { return a + b; });
assert(bar6714y((a, b){ return 1.0; }) == 1);
static assert(!__traits(compiles, {
bar6714y((a, b){ return 1.0f; });
}));
assert(bar6714y((a, b){ return a; }) == 2);
}
/***************************************************/
// 7193
void test7193()
{
static assert(!__traits(compiles, {
delete a => a;
}));
}
/***************************************************/
// 7207 : on CastExp
void test7202()
{
auto dg = cast(int function(int))(a => a);
assert(dg(10) == 10);
}
/***************************************************/
// 7288
void test7288()
{
// 7288 -> OK
auto foo()
{
int x;
return () => { return x; };
}
pragma(msg, typeof(&foo));
alias int delegate() nothrow @safe delegate() nothrow @safe delegate() Dg;
pragma(msg, Dg);
static assert(is(typeof(&foo) == Dg)); // should pass
}
/***************************************************/
// 7499
void test7499()
{
int function(int)[] a1 = [ x => x ]; // 7499
int function(int)[][] a2 = [[x => x]]; // +a
assert(a1[0] (10) == 10);
assert(a2[0][0](10) == 10);
}
/***************************************************/
// 7500
void test7500()
{
alias immutable bool function(int[]) Foo;
Foo f = a => true;
}
/***************************************************/
// 7525
void test7525()
{
{
char[] delegate() a = { return null; };
int delegate() b = { return 1U; };
uint delegate() c = { return 1; };
float delegate() d = { return 1.0; };
double delegate() e = { return 1.0f; };
}
{
char[] delegate(int) a = (x){ return null; };
int delegate(int) b = (x){ return 1U; };
uint delegate(int) c = (x){ return 1; };
float delegate(int) d = (x){ return 1.0; };
double delegate(int) e = (x){ return 1.0f; };
}
}
/***************************************************/
// 7582
void test7582()
{
void delegate(int) foo;
void delegate(int) foo2;
foo = (a) {
foo2 = (b) { };
};
}
/***************************************************/
// 7649
void test7649()
{
void foo(int function(int) fp = x => 1)
{
assert(fp(1) == 1);
}
foo();
}
/***************************************************/
// 7650
void test7650()
{
int[int function(int)] aa1 = [x=>x:1, x=>x*2:2];
foreach (k, v; aa1) {
if (v == 1) assert(k(10) == 10);
if (v == 2) assert(k(10) == 20);
}
int function(int)[int] aa2 = [1:x=>x, 2:x=>x*2];
assert(aa2[1](10) == 10);
assert(aa2[2](10) == 20);
int n = 10;
int[int delegate(int)] aa3 = [x=>n+x:1, x=>n+x*2:2];
foreach (k, v; aa3) {
if (v == 1) assert(k(10) == 20);
if (v == 2) assert(k(10) == 30);
}
int delegate(int)[int] aa4 = [1:x=>n+x, 2:x=>n+x*2];
assert(aa4[1](10) == 20);
assert(aa4[2](10) == 30);
}
/***************************************************/
// 7705
void test7705()
{
void foo1(void delegate(ref int ) dg){ int x=10; dg(x); }
foo1((ref x){ pragma(msg, typeof(x)); assert(x == 10); });
static assert(!__traits(compiles, foo1((x){}) ));
void foo2(void delegate(int, ...) dg){ dg(20, 3.14); }
foo2((x,...){ pragma(msg, typeof(x)); assert(x == 20); });
void foo3(void delegate(int[]...) dg){ dg(1, 2, 3); }
foo3((x ...){ pragma(msg, typeof(x)); assert(x == [1,2,3]); });
}
/***************************************************/
// 7713
void foo7713(T)(T delegate(in Object) dlg)
{}
void test7713()
{
foo7713( (in obj) { return 15; } ); // line 6
}
/***************************************************/
// 7743
auto foo7743a()
{
int x = 10;
return () nothrow {
return x;
};
}
auto foo7743b()
{
int x = 10;
return () nothrow => x;
}
void test7743()
{
static assert(is(typeof(&foo7743a) == int delegate() nothrow @safe function()));
assert(foo7743a()() == 10);
static assert(is(typeof(&foo7743b) == int delegate() nothrow @safe function()));
assert(foo7743b()() == 10);
}
/***************************************************/
// 7761
enum dg7761 = (int a) pure => 2 * a;
void test7761()
{
static assert(is(typeof(dg7761) == int function(int) pure @safe nothrow));
assert(dg7761(10) == 20);
}
/***************************************************/
// 7941
void test7941()
{
static assert(!__traits(compiles, { enum int c = function(){}; }));
}
/***************************************************/
// 8005
void test8005()
{
auto n = (a, int n = 2){ return n; }(1);
assert(n == 2);
}
/***************************************************/
// test8198
void test8198()
{
T delegate(T) zero(T)(T delegate(T) f)
{
return x => x;
}
T delegate(T) delegate(T delegate(T)) succ(T)(T delegate(T) delegate(T delegate(T)) n)
{
return f => x => f(n(f)(x));
}
uint delegate(uint) delegate(uint delegate(uint)) n = &zero!uint;
foreach (i; 0..10)
{
assert(n(x => x + 1)(0) == i);
n = succ(n);
}
}
/***************************************************/
// 8226
immutable f8226 = (int x) => x * 2;
void test8226()
{
assert(f8226(10) == 20);
}
/***************************************************/
// 8241
auto exec8241a(alias a = function(x) => x, T...)(T as)
{
return a(as);
}
auto exec8241b(alias a = (x) => x, T...)(T as)
{
return a(as);
}
void test8241()
{
exec8241a(2);
exec8241b(2);
}
/***************************************************/
// 8242
template exec8242(alias a, T...)
{
auto func8242(T as)
{
return a(as);
}
}
mixin exec8242!(x => x, int);
mixin exec8242!((string x) => x, string);
void test8242()
{
func8242(1);
func8242("");
}
/***************************************************/
// 8315
void test8315()
{
bool b;
foo8315!(a => b)();
}
void foo8315(alias pred)()
if (is(typeof(pred(1)) == bool))
{}
/***************************************************/
// 8397
void test8397()
{
void function(int) f;
static assert(!is(typeof({
f = function(string x) {};
})));
}
/***************************************************/
// 8496
void test8496()
{
alias extern (C) void function() Func;
Func fp = (){};
fp = (){};
}
/***************************************************/
// 8575
template tfunc8575(func...)
{
auto tfunc8575(U)(U u) { return func[0](u); }
}
auto bar8575(T)(T t)
{
return tfunc8575!(a => a)(t);
}
void foo8575a() { assert(bar8575(uint.init + 1) == +1); }
void foo8575b() { assert(bar8575( int.init - 1) == -1); }
void test8575()
{
foo8575a();
foo8575b();
}
/***************************************************/
// 9153
void writeln9153(string s){}
void test9153()
{
auto tbl1 = [
(string x) { writeln9153(x); },
(string x) { x ~= 'a'; },
];
auto tbl2 = [
(string x) { x ~= 'a'; },
(string x) { writeln9153(x); },
];
}
/***************************************************/
// 9393
template ifThrown9393a(E)
{
void ifThrown9393a(T)(scope T delegate(E) errHandler)
{
}
}
void ifThrown9393b(E, T)(scope T delegate(E) errHandler)
{
}
void foo9393(T)(void delegate(T) dg){ dg(T.init); }
void foo9393()(void delegate(int) dg){ foo9393!int(dg); }
void test9393()
{
ifThrown9393a!Exception(e => 10);
ifThrown9393b!Exception(e => 10);
foo9393((x){ assert(x == int.init); });
}
/***************************************************/
// 9415
void test9415()
{
int z;
typeof((int a){return z;}) dg;
dg = (int a){return z;};
}
/***************************************************/
// 9628
template TypeTuple9628(TL...) { alias TypeTuple9628 = TL; }
void map9628(alias func)() { func(0); }
void test9628()
{
auto items = [[10, 20], [30]];
size_t[] res;
res = null;
foreach (_; 0 .. 2)
{
foreach (sub; items)
{
map9628!(( i){ res ~= sub.length; });
map9628!((size_t i){ res ~= sub.length; });
}
}
assert(res == [2,2,1,1, 2,2,1,1]);
res = null;
foreach (_; TypeTuple9628!(0, 1))
{
foreach (sub; items)
{
map9628!(( i){ res ~= sub.length; });
map9628!((size_t i){ res ~= sub.length; });
}
}
assert(res == [2,2,1,1, 2,2,1,1]);
}
/***************************************************/
// 9928
void test9928()
{
void* smth = (int x) { return x; };
}
/***************************************************/
// 10288
T foo10288(T)(T x)
{
void lambda() @trusted nothrow { x += 10; }
lambda();
return x;
}
T bar10288(T)(T x)
{
() @trusted { x += 10; } ();
return x;
}
T baz10288(T)(T arg)
{
static int g = 10;
() @trusted { x += g; } ();
return x;
}
void test10288() @safe pure nothrow
{
assert(foo10288(10) == 20); // OK
assert(bar10288(10) == 20); // OK <- NG
static assert(!__traits(compiles, baz10288(10)));
}
/***************************************************/
// 10666
struct S10666
{
int val;
~this() {}
}
void foo10666(S10666 s1)
{
S10666 s2;
/* Even if closureVars(s1 and s2) are accessed by directly called lambdas,
* they won't escape the scope of this function.
*/
auto x1 = (){ return s1.val; }(); // OK
auto x2 = (){ return s2.val; }(); // OK
}
/***************************************************/
int main()
{
test1();
test2();
test3();
test4();
test4v();
test5();
test6();
test7();
test8();
test9();
test10();
test11();
test3235();
test6714();
test7193();
test7202();
test7288();
test7499();
test7500();
test7525();
test7582();
test7649();
test7650();
test7705();
test7713();
test7743();
test7761();
test7941();
test8005();
test8198();
test8226();
test8241();
test8242();
test8315();
test8397();
test8496();
test8575();
test9153();
test9393();
test9415();
test9628();
test9928();
test10288();
printf("Success\n");
return 0;
}