1 // PERMUTE_ARGS: -inline -g -O
2 
3 extern(C) int printf(const char*, ...);
4 
5 /*******************************************/
6 
7 class A
8 {
9     int x = 7;
10 
foo(int i)11     int foo(int i)
12     in
13     {
14         printf("A.foo.in %d\n", i);
15         assert(i == 2);
16         assert(x == 7);
17         printf("A.foo.in pass\n");
18     }
out(result)19     out (result)
20     {
21         assert(result & 1);
22         assert(x == 7);
23     }
24     do
25     {
26         return i;
27     }
28 }
29 
30 class B : A
31 {
foo(int i)32     override int foo(int i)
33     in
34     {
35         float f;
36         printf("B.foo.in %d\n", i);
37         assert(i == 4);
38         assert(x == 7);
39         f = f + i;
40     }
out(result)41     out (result)
42     {
43         assert(result < 8);
44         assert(x == 7);
45     }
46     do
47     {
48         return i - 1;
49     }
50 }
51 
test1()52 void test1()
53 {
54     auto b = new B();
55     b.foo(2);
56     b.foo(4);
57 }
58 
59 /*******************************************/
60 
61 class A2
62 {
63     int x = 7;
64 
foo(int i)65     int foo(int i)
66     in
67     {
68         printf("A2.foo.in %d\n", i);
69         assert(i == 2);
70         assert(x == 7);
71         printf("A2.foo.in pass\n");
72     }
out(result)73     out (result)
74     {
75         assert(result & 1);
76         assert(x == 7);
77     }
78     do
79     {
80         return i;
81     }
82 }
83 
84 class B2 : A2
85 {
foo(int i)86     override int foo(int i)
87     in
88     {
89         float f;
90         printf("B2.foo.in %d\n", i);
91         assert(i == 4);
92         assert(x == 7);
93         f = f + i;
94     }
out(result)95     out (result)
96     {
97         assert(result < 8);
98         assert(x == 7);
99     }
100     do
101     {
102         return i - 1;
103     }
104 }
105 
106 class C : B2
107 {
foo(int i)108     override int foo(int i)
109     in
110     {
111         float f;
112         printf("C.foo.in %d\n", i);
113         assert(i == 6);
114         assert(x == 7);
115         f = f + i;
116     }
out(result)117     out (result)
118     {
119         assert(result == 1 || result == 3 || result == 5);
120         assert(x == 7);
121     }
122     do
123     {
124         return i - 1;
125     }
126 }
127 
test2()128 void test2()
129 {
130     auto c = new C();
131     c.foo(2);
132     c.foo(4);
133     c.foo(6);
134 }
135 
136 /*******************************************/
137 
fun(int x)138 void fun(int x)
139 in {
140     if (x < 0) throw new Exception("a");
141 }
142 do {
143 }
144 
test3()145 void test3()
146 {
147     fun(1);
148 }
149 
150 /*******************************************/
151 
152 interface Stack {
pop()153     int pop()
154 //   in { printf("pop.in\n"); }
155     out(result) {
156         printf("pop.out\n");
157         assert(result == 3);
158     }
159 }
160 
161 class CC : Stack
162 {
pop()163     int pop()
164     //out (result) { printf("CC.pop.out\n"); } do
165     {
166         printf("CC.pop.in\n");
167         return 3;
168     }
169 }
170 
test4()171 void test4()
172 {
173     auto cc = new CC();
174     cc.pop();
175 }
176 
177 /*******************************************/
178 
mul100(int n)179 int mul100(int n)
180 out(result)
181 {
182     assert(result == 500);
183 }
184 do
185 {
186     return n * 100;
187 }
188 
test5()189 void test5()
190 {
191     mul100(5);
192 }
193 
194 /*******************************************/
195 // 3273
196 
197 // original case
198 struct Bug3273
199 {
~thisBug3273200     ~this() {}
invariantBug3273201     invariant() {}
202 }
203 
204 // simplest case
func3273()205 ref int func3273()
206 out(r)
207 {
208     // Regression check of issue 3390
209     static assert(!__traits(compiles, r = 1));
210 }
211 do
212 {
213     static int dummy;
214     return dummy;
215 }
216 
test6()217 void test6()
218 {
219     func3273() = 1;
220     assert(func3273() == 1);
221 }
222 
223 /*******************************************/
224 
225 /+
226 // http://d.puremagic.com/issues/show_bug.cgi?id=3722
227 
228 class Bug3722A
229 {
230     void fun() {}
231 }
232 class Bug3722B : Bug3722A
233 {
234     override void fun() in { assert(false); } do {}
235 }
236 
237 void test6()
238 {
239     auto x = new Bug3722B();
240     x.fun();
241 }
242 +/
243 
244 /*******************************************/
245 
test7foo()246 auto test7foo()
247 in{
248     ++cnt;
249 }do{
250     ++cnt;
251     return "str";
252 }
253 
test7()254 void test7()
255 {
256     cnt = 0;
257     assert(test7foo() == "str");
258     assert(cnt == 2);
259 }
260 
261 /*******************************************/
262 
foo8()263 auto foo8()
264 out(r){
265     ++cnt;
266     assert(r == 10);
267 }do{
268     ++cnt;
269     return 10;
270 }
271 
bar8()272 auto bar8()
273 out{
274     ++cnt;
275 }do{
276     ++cnt;
277 }
278 
test8()279 void test8()
280 {
281     cnt = 0;
282     assert(foo8() == 10);
283     assert(cnt == 2);
284 
285     cnt = 0;
286     bar8();
287     assert(cnt == 2);
288 }
289 
290 /*******************************************/
291 // from fail317
292 
test9()293 void test9()
294 {
295   {
296     auto f1 = function() do { }; // fine
297     auto f2 = function() in { } do { }; // fine
298     auto f3 = function() out { } do { }; // error
299     auto f4 = function() in { } out { } do { }; // error
300 
301     auto d1 = delegate() do { }; // fine
302     auto d2 = delegate() in { } do { }; // fine
303     auto d3 = delegate() out { } do { }; // error
304     auto d4 = delegate() in { } out { } do { }; // error
305   }
306   {
307     auto f1 = function() body { }; // fine
308     auto f2 = function() in { } body { }; // fine
309     auto f3 = function() out { } body { }; // error
310     auto f4 = function() in { } out { } body { }; // error
311 
312     auto d1 = delegate() body { }; // fine
313     auto d2 = delegate() in { } body { }; // fine
314     auto d3 = delegate() out { } body { }; // error
315     auto d4 = delegate() in { } out { } body { }; // error
316   }
317 }
318 
319 /*******************************************/
320 
test10()321 auto test10() body { return 3; }
test11()322 auto test11()() body { return 3; }
323 
test12()324 auto test12()
325 {
326     auto test10() body { return 3; }
327     auto test11()() body { return 3; }
328     return 3;
329 }
330 
331 
test13()332 void test13()
333 {
334     int function() fp13;
335 }
336 
337 /*******************************************/
338 // 4785
339 
340 int cnt;
341 
foo4785()342 auto foo4785()
343 in{
344     int r;
345     ++cnt;
346 }
out(r)347 out(r){
348     assert(r == 10);
349     ++cnt;
350 }do{
351     ++cnt;
352     int r = 10;
353     return r;
354 }
test4785()355 void test4785()
356 {
357     cnt = 0;
358     assert(foo4785() == 10);
359     assert(cnt == 3);
360 }
361 
362 /*******************************************/
363 // 5039
364 
365 class C5039 {
366     int x;
367 
invariant()368     invariant() {
369         assert( x < int.max );
370     }
371 
foo()372     auto foo() {
373         return x;
374     }
375 }
376 
377 /*******************************************/
378 // 5204
379 
380 interface IFoo5204
381 {
bar()382     IFoo5204 bar()
383     out {}
384 }
385 class Foo5204 : IFoo5204
386 {
bar()387     Foo5204 bar() { return null; }
388 }
389 
390 /*******************************************/
391 // 6417
392 
393 class Bug6417
394 {
bar()395     void bar()
396     in
397     {
398         int i = 14;
399         assert(i == 14);
400         auto dg = (){
401             //printf("in: i = %d\n", i);
402             assert(i == 14, "in contract failure");
403         };
404         dg();
405     }
406     out
407     {
408         int j = 10;
409         assert(j == 10);
410         auto dg = (){
411             //printf("out: j = %d\n", j);
412             assert(j == 10, "out contract failure");
413         };
414         dg();
415     }
416     do {}
417 }
418 
test6417()419 void test6417()
420 {
421     (new Bug6417).bar();
422 }
423 
424 /*******************************************/
425 // 7218
426 
test7218()427 void test7218()
428 {
429   {
430     size_t foo()  in{}  out{}  do{ return 0; } // OK
431     size_t bar()  in{}/*out{}*/do{ return 0; } // OK
432     size_t hoo()/*in{}*/out{}  do{ return 0; } // NG1
433     size_t baz()/*in{}  out{}*/do{ return 0; } // NG2
434   }
435   {
436     size_t goo()  in{}  out{}  body{ return 0; } // OK
437     size_t gar()  in{}/*out{}*/body{ return 0; } // OK
438     size_t gob()/*in{}*/out{}  body{ return 0; } // NG1
439     size_t gaz()/*in{}  out{}*/body{ return 0; } // NG2
440   }
441 }
442 
443 /*******************************************/
444 // 7517
445 
test7517()446 void test7517()
447 {
448     static string result;
449 
450     interface I
451     {
452         static I self;
453 
454         void setEnable()
455         in
456         {
457             assert(self is this);
458             result ~= "I.setEnable.in/";
459             assert(!enabled);
460         }
461         out
462         {
463             assert(self is this);
464             result ~= "I.setEnable.out/";
465             assert( enabled);
466         }
467 
468         void setDisable()
469         in
470         {
471             assert(self is this);
472             result ~= "I.setDisable.in/";
473             assert( enabled);
474         }
475         out
476         {
477             assert(self is this);
478             result ~= "I.setDisable.out/";
479             assert(!enabled);
480         }
481 
482         @property bool enabled() const;
483     }
484 
485     class C : I
486     {
487         static C self;
488 
489         void setEnable()
490         in {}       // supply in-contract to invoke I.setEnable.in
491         do
492         {
493             assert(self is this);
494             result ~= "C.setEnable/";
495             _enabled = true;
496         }
497 
498         void setDisable()
499         {
500             assert(self is this);
501             result ~= "C.setDisable/";
502             _enabled = false;
503         }
504 
505         @property bool enabled() const
506         {
507             assert(self is this);
508             result ~= "C.enabled/";
509             return _enabled;
510         }
511 
512         bool _enabled;
513     }
514 
515     C c = C.self = new C;
516     I i = I.self = c;
517 
518     result = null;
519     i.setEnable();
520     assert(result == "I.setEnable.in/C.enabled/C.setEnable/I.setEnable.out/C.enabled/");
521 
522     result = null;
523     i.setDisable();
524     assert(result == "C.setDisable/I.setDisable.out/C.enabled/");
525 }
526 
527 /*******************************************/
528 // 7699
529 
530 class P7699
531 {
f(int n)532     void f(int n) in {
533         assert (n);
534     } do { }
535 }
536 class D7699 : P7699
537 {
f(int n)538     override void f(int n) in { } do { }
539 }
540 
541 /*******************************************/
542 // 7883
543 
544 // Segmentation fault
545 class AA7883
546 {
foo()547     int foo()
548     out (r1) { }
549     do { return 1; }
550 }
551 
552 class BA7883 : AA7883
553 {
foo()554     override int foo()
555     out (r2) { }
556     do { return 1; }
557 }
558 
559 class CA7883 : BA7883
560 {
561     override int foo()
562     do { return 1; }
563 }
564 
565 // Error: undefined identifier r2, did you mean variable r3?
566 class AB7883
567 {
foo()568     int foo()
569     out (r1) { }
570     do { return 1; }
571 }
572 
573 class BB7883 : AB7883
574 {
foo()575     override int foo()
576     out (r2) { }
577     do { return 1; }
578 
579 }
580 
581 class CB7883 : BB7883
582 {
foo()583     override int foo()
584     out (r3) { }
585     do { return 1; }
586 }
587 
588 // Error: undefined identifier r3, did you mean variable r4?
589 class AC7883
590 {
foo()591     int foo()
592     out (r1) { }
593     do { return 1; }
594 }
595 
596 class BC7883 : AC7883
597 {
foo()598     override int foo()
599     out (r2) { }
600     do { return 1; }
601 }
602 
603 class CC7883 : BC7883
604 {
foo()605     override int foo()
606     out (r3) { }
607     do { return 1; }
608 }
609 
610 class DC7883 : CC7883
611 {
foo()612     override int foo()
613     out (r4) { }
614     do { return 1; }
615 }
616 
617 /*******************************************/
618 // 7892
619 
620 struct S7892
621 {
622     @disable this();
thisS7892623     this(int x) {}
624 }
625 
f7892()626 S7892 f7892()
627 out (result) {}     // case 1
628 do
629 {
630     return S7892(1);
631 }
632 
633 interface I7892
634 {
635     S7892 f();
636 }
637 class C7892
638 {
invariant()639     invariant() {}  // case 2
640 
f()641     S7892 f()
642     {
643         return S7892(1);
644     }
645 }
646 
647 /*******************************************/
648 // 8066
649 
650 struct CLCommandQueue
651 {
invariantCLCommandQueue652     invariant() {}
653 
654 //private:
enqueueNativeKernelCLCommandQueue655     int enqueueNativeKernel()
656     {
657         assert(0, "implement me");
658     }
659 }
660 
661 /*******************************************/
662 // 8073
663 
664 struct Container8073
665 {
opApply(int delegate (ref int)dg)666     int opApply (int delegate(ref int) dg) { return 0; }
667 }
668 
669 class Bug8073
670 {
671     static int test;
foo()672     int foo()
673     out(r) { test = 7; } do
674     {
675         Container8073 ww;
foreach(xxx;ww)676         foreach( xxx ; ww ) {  }
677         return 7;
678     }
679 
bar()680     ref int bar()
681     out { } do
682     {
683         Container8073 ww;
foreach(xxx;ww)684         foreach( xxx ; ww ) {  }
685         test = 7;
686         return test;
687     }
688 }
test8073()689 void test8073()
690 {
691     auto c = new Bug8073();
692     assert(c.foo() == 7);
693     assert(c.test == 7);
694 
695     auto p = &c.bar();
696     assert(p == &c.test);
697     assert(*p == 7);
698 }
699 
700 /*******************************************/
701 // 8093
702 
test8093()703 void test8093()
704 {
705     static int g = 10;
706     static int* p;
707 
708     enum fdo = q{
709         static struct S {
710             int opApply(scope int delegate(ref int) dg) { return dg(g); }
711         }
712         S s;
713         foreach (ref e; s)
714             return g;
715         assert(0);
716     };
717 
718     ref int foo_ref1() out(r) { assert(&r is &g && r == 10); }
719     do { mixin(fdo); }
720 
721     ref int foo_ref2()
722     do { mixin(fdo); }
723 
724     { auto q = &foo_ref1(); assert(q is &g && *q == 10); }
725     { auto q = &foo_ref2(); assert(q is &g && *q == 10); }
726 
727     int foo_val1() out(r) { assert(&r !is &g && r == 10); }
728     do { mixin(fdo); }
729 
730     int foo_val2()
731     do { mixin(fdo); }
732 
733     { auto n = foo_val1(); assert(&n !is &g && n == 10); }
734     { auto n = foo_val2(); assert(&n !is &g && n == 10); }
735 }
736 
737 /*******************************************/
738 // 9383
739 
740 class A9383
741 {
742     static void delegate() dg;
743     static int val;
744 
failInBase()745     void failInBase() { assert(typeid(this) is typeid(A9383)); }
746 
747     // in-contract tests
foo1(int i)748     void foo1(int i) in  { A9383.val = i; failInBase; } do { }                        // no closure
foo2(int i)749     void foo2(int i) in  { A9383.val = i; failInBase; } do { int x; dg = { ++x; }; }  // closure [local]
foo3(int i)750     void foo3(int i) in  { A9383.val = i; failInBase; } do {        dg = { ++i; }; }  // closure [parameter]
foo4(int i)751     void foo4(int i) in  { A9383.val = i; failInBase; } do { }                        // no closure
foo5(int i)752     void foo5(int i) in  { A9383.val = i; failInBase; } do { }                        // no closure
foo6(int i)753     void foo6(int i) in  { A9383.val = i; failInBase; } do { int x; dg = { ++x; }; }  // closure [local]
foo7(int i)754     void foo7(int i) in  { A9383.val = i; failInBase; } do {        dg = { ++i; }; }  // closure [parameter]
755 
756     // out-contract tests
bar1(int i)757     void bar1(int i) out { A9383.val = i;             } do { }                        // no closure
bar2(int i)758     void bar2(int i) out { A9383.val = i;             } do { int x; dg = { ++x; }; }  // closure [local]
bar3(int i)759     void bar3(int i) out { A9383.val = i;             } do {        dg = { ++i; }; }  // closure [parameter]
bar4(int i)760     void bar4(int i) out { A9383.val = i;             } do { }                        // no closure
bar5(int i)761     void bar5(int i) out { A9383.val = i;             } do { }                        // no closure
bar6(int i)762     void bar6(int i) out { A9383.val = i;             } do { int x; dg = { ++x; }; }  // closure [local]
bar7(int i)763     void bar7(int i) out { A9383.val = i;             } do {        dg = { ++i; }; }  // closure [parameter]
764 }
765 
766 class B9383 : A9383
767 {
768     static int val;
769 
770     // in-contract tests
foo1(int i)771     override void foo1(int i) in  { B9383.val = i; } do { }                           // -> no closure
foo2(int i)772     override void foo2(int i) in  { B9383.val = i; } do { int x; dg = { ++x; }; }     // -> closure [local] appears
foo3(int i)773     override void foo3(int i) in  { B9383.val = i; } do {        dg = { ++i; }; }     // -> closure [parameter]
foo4(int i)774     override void foo4(int i) in  { B9383.val = i; } do { int x; dg = { ++x; }; }     // -> closure [local] appears
foo5(int i)775     override void foo5(int i) in  { B9383.val = i; } do {        dg = { ++i; }; }     // -> closure [parameter] appears
foo6(int i)776     override void foo6(int i) in  { B9383.val = i; } do { }                           // -> closure [local] disappears
foo7(int i)777     override void foo7(int i) in  { B9383.val = i; } do { }                           // -> closure [parameter] disappears
778 
779     // out-contract tests
bar1(int i)780     override void bar1(int i) out { B9383.val = i; } do { }                           // -> no closure
bar2(int i)781     override void bar2(int i) out { B9383.val = i; } do { int x; dg = { ++x; }; }     // -> closure [local] appears
bar3(int i)782     override void bar3(int i) out { B9383.val = i; } do {        dg = { ++i; }; }     // -> closure [parameter]
bar4(int i)783     override void bar4(int i) out { B9383.val = i; } do { int x; dg = { ++x; }; }     // -> closure [local] appears
bar5(int i)784     override void bar5(int i) out { B9383.val = i; } do {        dg = { ++i; }; }     // -> closure [parameter] appears
bar6(int i)785     override void bar6(int i) out { B9383.val = i; } do { }                           // -> closure [local] disappears
bar7(int i)786     override void bar7(int i) out { B9383.val = i; } do { }                           // -> closure [parameter] disappears
787 }
788 
test9383()789 void test9383()
790 {
791     auto a = new A9383();
792     auto b = new B9383();
793 
794     // base class in-contract is used from derived class.       // base                   derived
795     b.foo1(101); assert(A9383.val == 101 && B9383.val == 101);  // no closure          -> no closure
796     b.foo2(102); assert(A9383.val == 102 && B9383.val == 102);  // closure [local]     -> closure [local] appears
797     b.foo3(103); assert(A9383.val == 103 && B9383.val == 103);  // closure [parameter] -> closure [parameter]
798     b.foo4(104); assert(A9383.val == 104 && B9383.val == 104);  // no closure          -> closure [local] appears
799     b.foo5(105); assert(A9383.val == 105 && B9383.val == 105);  // no closure          -> closure [parameter] appears
800     b.foo6(106); assert(A9383.val == 106 && B9383.val == 106);  // closure [local]     -> closure [local] disappears
801     b.foo7(107); assert(A9383.val == 107 && B9383.val == 107);  // closure [parameter] -> closure [parameter] disappears
802 
803     // base class out-contract is used from derived class.      // base                   derived
804     b.bar1(101); assert(A9383.val == 101 && B9383.val == 101);  // no closure          -> no closure
805     b.bar2(102); assert(A9383.val == 102 && B9383.val == 102);  // closure [local]     -> closure [local] appears
806     b.bar3(103); assert(A9383.val == 103 && B9383.val == 103);  // closure [parameter] -> closure [parameter]
807     b.bar4(104); assert(A9383.val == 104 && B9383.val == 104);  // no closure          -> closure [local] appears
808     b.bar5(105); assert(A9383.val == 105 && B9383.val == 105);  // no closure          -> closure [parameter] appears
809     b.bar6(106); assert(A9383.val == 106 && B9383.val == 106);  // closure [local]     -> closure [local] disappears
810     b.bar7(107); assert(A9383.val == 107 && B9383.val == 107);  // closure [parameter] -> closure [parameter] disappears
811 
812     // in-contract in base class.
813     a.foo1(101); assert(A9383.val == 101);      // no closure
814     a.foo2(102); assert(A9383.val == 102);      // closure [local]
815     a.foo3(103); assert(A9383.val == 103);      // closure [parameter]
816 
817     // out-contract in base class.
818     a.bar1(101); assert(A9383.val == 101);      // no closure
819     a.bar2(102); assert(A9383.val == 102);      // closure [local]
820     a.bar3(103); assert(A9383.val == 103);      // closure [parameter]
821 }
822 
823 /*******************************************/
824 // 15524 - Different from issue 9383 cases, closed variable size is bigger than REGSIZE.
825 
826 class A15524
827 {
828     static void delegate() dg;
829     static string val;
830 
failInBase()831     void failInBase() { assert(typeid(this) is typeid(A15524)); }
832 
833     // in-contract tests
foo1(string s)834     void foo1(string s) in  { A15524.val = s; failInBase; } do { }                                // no closure
foo2(string s)835     void foo2(string s) in  { A15524.val = s; failInBase; } do { string x; dg = { x = null; }; }  // closure [local]
foo3(string s)836     void foo3(string s) in  { A15524.val = s; failInBase; } do {           dg = { s = null; }; }  // closure [parameter]
foo4(string s)837     void foo4(string s) in  { A15524.val = s; failInBase; } do { }                                // no closure
foo5(string s)838     void foo5(string s) in  { A15524.val = s; failInBase; } do { }                                // no closure
foo6(string s)839     void foo6(string s) in  { A15524.val = s; failInBase; } do { string x; dg = { x = null; }; }  // closure [local]
foo7(string s)840     void foo7(string s) in  { A15524.val = s; failInBase; } do {           dg = { s = null; }; }  // closure [parameter]
841 
842     // out-contract tests
bar1(string s)843     void bar1(string s) out { A15524.val = s;             } do { }                                // no closure
bar2(string s)844     void bar2(string s) out { A15524.val = s;             } do { string x; dg = { x = null; }; }  // closure [local]
bar3(string s)845     void bar3(string s) out { A15524.val = s;             } do {           dg = { s = null; }; }  // closure [parameter]
bar4(string s)846     void bar4(string s) out { A15524.val = s;             } do { }                                // no closure
bar5(string s)847     void bar5(string s) out { A15524.val = s;             } do { }                                // no closure
bar6(string s)848     void bar6(string s) out { A15524.val = s;             } do { string x; dg = { x = null; }; }  // closure [local]
bar7(string s)849     void bar7(string s) out { A15524.val = s;             } do {           dg = { s = null; }; }  // closure [parameter]
850 }
851 
852 class B15524 : A15524
853 {
854     static string val;
855 
856     // in-contract tests
foo1(string s)857     override void foo1(string s) in  { B15524.val = s; } do { }                                   // -> no closure
foo2(string s)858     override void foo2(string s) in  { B15524.val = s; } do { string x; dg = { x = null; }; }     // -> closure [local] appears
foo3(string s)859     override void foo3(string s) in  { B15524.val = s; } do {           dg = { s = null; }; }     // -> closure [parameter]
foo4(string s)860     override void foo4(string s) in  { B15524.val = s; } do { string x; dg = { x = null; }; }     // -> closure [local] appears
foo5(string s)861     override void foo5(string s) in  { B15524.val = s; } do {           dg = { s = null; }; }     // -> closure [parameter] appears
foo6(string s)862     override void foo6(string s) in  { B15524.val = s; } do { }                                   // -> closure [local] disappears
foo7(string s)863     override void foo7(string s) in  { B15524.val = s; } do { }                                   // -> closure [parameter] disappears
864 
865     // out-contract tests
bar1(string s)866     override void bar1(string s) out { B15524.val = s; } do { }                                   // -> no closure
bar2(string s)867     override void bar2(string s) out { B15524.val = s; } do { string x; dg = { x = null; }; }     // -> closure [local] appears
bar3(string s)868     override void bar3(string s) out { B15524.val = s; } do {           dg = { s = null; }; }     // -> closure [parameter]
bar4(string s)869     override void bar4(string s) out { B15524.val = s; } do { string x; dg = { x = null; }; }     // -> closure [local] appears
bar5(string s)870     override void bar5(string s) out { B15524.val = s; } do {           dg = { s = null; }; }     // -> closure [parameter] appears
bar6(string s)871     override void bar6(string s) out { B15524.val = s; } do { }                                   // -> closure [local] disappears
bar7(string s)872     override void bar7(string s) out { B15524.val = s; } do { }                                   // -> closure [parameter] disappears
873 }
874 
test15524()875 void test15524()
876 {
877     auto a = new A15524();
878     auto b = new B15524();
879 
880     // base class in-contract is used from derived class.           // base                   derived
881     b.foo1("1"); assert(A15524.val == "1" && B15524.val == "1");    // no closure          -> no closure
882     b.foo2("2"); assert(A15524.val == "2" && B15524.val == "2");    // closure [local]     -> closure [local] appears
883     b.foo3("3"); assert(A15524.val == "3" && B15524.val == "3");    // closure [parameter] -> closure [parameter]
884     b.foo4("4"); assert(A15524.val == "4" && B15524.val == "4");    // no closure          -> closure [local] appears
885     b.foo5("5"); assert(A15524.val == "5" && B15524.val == "5");    // no closure          -> closure [parameter] appears
886     b.foo6("6"); assert(A15524.val == "6" && B15524.val == "6");    // closure [local]     -> closure [local] disappears
887     b.foo7("7"); assert(A15524.val == "7" && B15524.val == "7");    // closure [parameter] -> closure [parameter] disappears
888 
889     // base class out-contract is used from derived class.          // base                   derived
890     b.bar1("1"); assert(A15524.val == "1" && B15524.val == "1");    // no closure          -> no closure
891     b.bar2("2"); assert(A15524.val == "2" && B15524.val == "2");    // closure [local]     -> closure [local] appears
892     b.bar3("3"); assert(A15524.val == "3" && B15524.val == "3");    // closure [parameter] -> closure [parameter]
893     b.bar4("4"); assert(A15524.val == "4" && B15524.val == "4");    // no closure          -> closure [local] appears
894     b.bar5("5"); assert(A15524.val == "5" && B15524.val == "5");    // no closure          -> closure [parameter] appears
895     b.bar6("6"); assert(A15524.val == "6" && B15524.val == "6");    // closure [local]     -> closure [local] disappears
896     b.bar7("7"); assert(A15524.val == "7" && B15524.val == "7");    // closure [parameter] -> closure [parameter] disappears
897 
898     // in-contract in base class.
899     a.foo1("1"); assert(A15524.val == "1");     // no closure
900     a.foo2("2"); assert(A15524.val == "2");     // closure [local]
901     a.foo3("3"); assert(A15524.val == "3");     // closure [parameter]
902 
903     // out-contract in base class.
904     a.bar1("1"); assert(A15524.val == "1");     // no closure
905     a.bar2("2"); assert(A15524.val == "2");     // closure [local]
906     a.bar3("3"); assert(A15524.val == "3");     // closure [parameter]
907 }
908 
test15524a()909 void test15524a()
910 {
911     auto t1 = new Test15524a();
912     t1.infos["first"] = 0; //t1.add("first");
913     t1.add("second");
914 
915     auto t2 = new Test15524b();
916     t2.add("second");
917 }
918 
919 class Test15524a
920 {
921     int[string] infos;
922 
add(string key)923     void add(string key)
924     in
925     {
926         assert(key !in infos); // @@@ crash here at second
927     }
928     do
929     {
930         auto item = new class
931         {
notCalled()932             void notCalled()
933             {
934                 infos[key] = 0;
935                     // affects, key parameter is made a closure variable.
936             }
937         };
938     }
939 }
940 
941 class Test15524b
942 {
add(string key)943     void add(string key)
944     in
945     {
946         assert(key == "second"); // @@@ fails
947     }
948     do
949     {
950         static void delegate() dg;
951         dg = { auto x = key; };
952             // affects, key parameter is made a closure variable.
953     }
954 }
955 
956 /*******************************************/
957 // 10479
958 
959 class B10479
960 {
foo()961     B10479 foo()
962     out { } do { return null; }
963 }
964 
965 class D10479 : B10479
966 {
foo()967     override D10479 foo() { return null; }
968 }
969 
970 /*******************************************/
971 // 10596
972 
973 class Foo10596
974 {
bar()975     auto bar()
976     out (result) { }
977     do { return 0; }
978 }
979 
980 /*******************************************/
981 // 10721
982 
983 class Foo10721
984 {
this()985     this()
986     out { }
987     do { }
988 
~this()989     ~this()
990     out { }
991     do { }
992 }
993 
994 struct Bar10721
995 {
thisBar10721996     this(this)
997     out { }
998     do { }
999 }
1000 
1001 /*******************************************/
1002 // 10981
1003 
1004 class C10981
1005 {
foo(int i)1006     void foo(int i) pure
1007     in { assert(i); }
1008     out { assert(i); }
1009     do {}
1010 }
1011 
1012 /*******************************************/
1013 // 14779
1014 
1015 class C14779
1016 {
foo(int v)1017     final void foo(int v)
1018     in  { assert(v == 0); }
1019     out { assert(v == 0); }
1020     do
1021     {
1022     }
1023 }
1024 
test14779()1025 void test14779()
1026 {
1027     auto c = new C14779();
1028     c.foo(0);
1029 }
1030 
1031 /*******************************************/
1032 
main()1033 int main()
1034 {
1035     test1();
1036     test2();
1037     test3();
1038     test4();
1039     test5();
1040 //    test6();
1041     test7();
1042     test8();
1043     test9();
1044     test4785();
1045     test6417();
1046     test7218();
1047     test7517();
1048     test8073();
1049     test8093();
1050     test9383();
1051     test15524();
1052     test15524a();
1053     test14779();
1054 
1055     printf("Success\n");
1056     return 0;
1057 }
1058