1 /* PERMUTE_ARGS: -inline -g -O
3 extern(C
) int printf(const char*, ...);
5 /*******************************************/
14 printf("A.foo.in %d\n", i
);
17 printf("A.foo.in pass\n");
32 override int foo(int i
)
36 printf("B.foo.in %d\n", i
);
59 /*******************************************/
68 printf("A2.foo.in %d\n", i
);
71 printf("A2.foo.in pass\n");
86 override int foo(int i
)
90 printf("B2.foo.in %d\n", i
);
108 override int foo(int i
)
112 printf("C.foo.in %d\n", i
);
119 assert(result
== 1 || result
== 3 || result
== 5);
136 /*******************************************/
140 if (x
< 0) throw new Exception("a");
150 /*******************************************/
154 // in { printf("pop.in\n"); }
164 //out (result) { printf("CC.pop.out\n"); } do
166 printf("CC.pop.in\n");
177 /*******************************************/
182 assert(result
== 500);
194 /*******************************************/
195 // https://issues.dlang.org/show_bug.cgi?id=3273
208 // Regression check of https://issues.dlang.org/show_bug.cgi?id=3390
209 static assert(!__traits(compiles
, r
= 1));
220 assert(func3273() == 1);
223 /*******************************************/
226 // https://issues.dlang.org/show_bug.cgi?id=3722
232 class Bug3722B : Bug3722A
234 override void fun() in { assert(false); } do {}
239 auto x = new Bug3722B();
244 /*******************************************/
257 assert(test7foo() == "str");
261 /*******************************************/
282 assert(foo8() == 10);
290 /*******************************************/
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
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
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
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
319 /*******************************************/
321 auto test10() do { return 3; }
322 auto test11()() do { return 3; }
326 auto test10() do { return 3; }
327 auto test11()() do { return 3; }
337 /*******************************************/
338 // https://issues.dlang.org/show_bug.cgi?id=4785
358 assert(foo4785() == 10);
362 /*******************************************/
363 // https://issues.dlang.org/show_bug.cgi?id=5039
369 assert( x
< int.max
);
377 /*******************************************/
378 // https://issues.dlang.org/show_bug.cgi?id=5204
385 class Foo5204
: IFoo5204
387 Foo5204
bar() { return null; }
390 /*******************************************/
391 // https://issues.dlang.org/show_bug.cgi?id=6417
401 //printf("in: i = %d\n", i);
402 assert(i
== 14, "in contract failure");
411 //printf("out: j = %d\n", j);
412 assert(j
== 10, "out contract failure");
424 /*******************************************/
425 // https://issues.dlang.org/show_bug.cgi?id=6549
429 static int ocount
= 0;
430 static int icount
= 0;
432 abstract int foo(int)
439 override int foo(int)
440 in { assert(false); }
446 static int icount
= 0;
447 static int ocount
= 0;
456 override int foo(int)
457 in { assert(false); }
465 assert(C6549
.icount
== 1);
466 assert(C6549
.ocount
== 1);
470 assert(D6549
.icount
== 1);
471 assert(D6549
.ocount
== 1);
474 /*******************************************/
475 // https://issues.dlang.org/show_bug.cgi?id=7218
480 size_t
foo() in{} out{} do{ return 0; } // OK
481 size_t
bar() in{}/*out{}*/do{ return 0; } // OK
482 size_t
hoo()/*in{}*/out{} do{ return 0; } // NG1
483 size_t
baz()/*in{} out{}*/do{ return 0; } // NG2
486 size_t
goo() in{} out{} body{ return 0; } // OK
487 size_t
gar() in{}/*out{}*/body{ return 0; } // OK
488 size_t
gob()/*in{}*/out{} body{ return 0; } // NG1
489 size_t
gaz()/*in{} out{}*/body{ return 0; } // NG2
493 /*******************************************/
494 // https://issues.dlang.org/show_bug.cgi?id=7335
500 void setValue(int newValue
)
502 out { assert(mValue
== 3); }
511 override void setValue(int newValue
)
512 in { assert(false); }
513 out { assert(mValue
== 3); }
522 override void setValue(int newValue
)
523 in { int a
= newValue
; }
524 out { assert(mValue
== 3); }
533 A7335 aObject
= new B7335();
536 A7335 bObject
= new C7335();
537 bObject
.setValue(3); // <<<<< will crash because undefined mValue in the
538 // A7335.setValue().out-block.
541 /*******************************************/
542 // https://issues.dlang.org/show_bug.cgi?id=7517
546 static string result
;
555 assert(self
is this);
556 result
~= "I.setEnable.in/";
561 assert(self
is this);
562 result
~= "I.setEnable.out/";
569 assert(self
is this);
570 result
~= "I.setDisable.in/";
575 assert(self
is this);
576 result
~= "I.setDisable.out/";
580 @property bool enabled() const;
588 in {} // supply in-contract to invoke I.setEnable.in
591 assert(self
is this);
592 result
~= "C.setEnable/";
598 assert(self
is this);
599 result
~= "C.setDisable/";
603 @property bool enabled() const
605 assert(self
is this);
606 result
~= "C.enabled/";
613 C c
= C
.self
= new C
;
618 assert(result
== "I.setEnable.in/C.enabled/C.setEnable/I.setEnable.out/C.enabled/");
622 assert(result
== "C.setDisable/I.setDisable.out/C.enabled/");
625 /*******************************************/
626 // https://issues.dlang.org/show_bug.cgi?id=7699
636 override void f(int n
) in { } do { }
639 /*******************************************/
640 // https://issues.dlang.org/show_bug.cgi?id=7883
642 // Segmentation fault
650 class BA7883
: AA7883
657 class CA7883
: BA7883
663 // Error: undefined identifier r2, did you mean variable r3?
671 class BB7883
: AB7883
679 class CB7883
: BB7883
686 // Error: undefined identifier r3, did you mean variable r4?
694 class BC7883
: AC7883
701 class CC7883
: BC7883
708 class DC7883
: CC7883
715 /*******************************************/
716 // https://issues.dlang.org/show_bug.cgi?id=7892
725 out (result
) {} // case 1
737 invariant() {} // case 2
745 /*******************************************/
746 // https://issues.dlang.org/show_bug.cgi?id=8066
748 struct CLCommandQueue
753 int enqueueNativeKernel()
755 assert(0, "implement me");
759 /*******************************************/
760 // https://issues.dlang.org/show_bug.cgi?id=8073
764 int opApply (int delegate(ref int) dg
) { return 0; }
771 out(r
) { test = 7; } do
774 foreach( xxx
; ww
) { }
782 foreach( xxx
; ww
) { }
789 auto c
= new Bug8073();
790 assert(c
.foo() == 7);
794 assert(p
== &c
.test);
798 /*******************************************/
799 // https://issues.dlang.org/show_bug.cgi?id=8093
808 int opApply(scope int delegate(ref int) dg
) { return dg(g
); }
816 ref int foo_ref1() out(r
) { assert(&r
is &g
&& r
== 10); }
822 { auto q
= &foo_ref1(); assert(q
is &g
&& *q
== 10); }
823 { auto q
= &foo_ref2(); assert(q
is &g
&& *q
== 10); }
825 int foo_val1() out(r
) { assert(&r
!is &g
&& r
== 10); }
831 { auto n
= foo_val1(); assert(&n
!is &g
&& n
== 10); }
832 { auto n
= foo_val2(); assert(&n
!is &g
&& n
== 10); }
835 /*******************************************/
836 // https://issues.dlang.org/show_bug.cgi?id=9383
840 static void delegate() dg
;
843 void failInBase() { assert(typeid(this) is typeid(A9383
)); }
846 void foo1(int i
) in { A9383
.val
= i
; failInBase
; } do { } // no closure
847 void foo2(int i
) in { A9383
.val
= i
; failInBase
; } do { int x
; dg
= { ++x
; }; } // closure [local]
848 void foo3(int i
) in { A9383
.val
= i
; failInBase
; } do { dg
= { ++i
; }; } // closure [parameter]
849 void foo4(int i
) in { A9383
.val
= i
; failInBase
; } do { } // no closure
850 void foo5(int i
) in { A9383
.val
= i
; failInBase
; } do { } // no closure
851 void foo6(int i
) in { A9383
.val
= i
; failInBase
; } do { int x
; dg
= { ++x
; }; } // closure [local]
852 void foo7(int i
) in { A9383
.val
= i
; failInBase
; } do { dg
= { ++i
; }; } // closure [parameter]
854 // out-contract tests
855 void bar1(int i
) out { A9383
.val
= i
; } do { } // no closure
856 void bar2(int i
) out { A9383
.val
= i
; } do { int x
; dg
= { ++x
; }; } // closure [local]
857 void bar3(int i
) out { A9383
.val
= i
; } do { dg
= { ++i
; }; } // closure [parameter]
858 void bar4(int i
) out { A9383
.val
= i
; } do { } // no closure
859 void bar5(int i
) out { A9383
.val
= i
; } do { } // no closure
860 void bar6(int i
) out { A9383
.val
= i
; } do { int x
; dg
= { ++x
; }; } // closure [local]
861 void bar7(int i
) out { A9383
.val
= i
; } do { dg
= { ++i
; }; } // closure [parameter]
869 override void foo1(int i
) in { B9383
.val
= i
; } do { } // -> no closure
870 override void foo2(int i
) in { B9383
.val
= i
; } do { int x
; dg
= { ++x
; }; } // -> closure [local] appears
871 override void foo3(int i
) in { B9383
.val
= i
; } do { dg
= { ++i
; }; } // -> closure [parameter]
872 override void foo4(int i
) in { B9383
.val
= i
; } do { int x
; dg
= { ++x
; }; } // -> closure [local] appears
873 override void foo5(int i
) in { B9383
.val
= i
; } do { dg
= { ++i
; }; } // -> closure [parameter] appears
874 override void foo6(int i
) in { B9383
.val
= i
; } do { } // -> closure [local] disappears
875 override void foo7(int i
) in { B9383
.val
= i
; } do { } // -> closure [parameter] disappears
877 // out-contract tests
878 override void bar1(int i
) out { B9383
.val
= i
; } do { } // -> no closure
879 override void bar2(int i
) out { B9383
.val
= i
; } do { int x
; dg
= { ++x
; }; } // -> closure [local] appears
880 override void bar3(int i
) out { B9383
.val
= i
; } do { dg
= { ++i
; }; } // -> closure [parameter]
881 override void bar4(int i
) out { B9383
.val
= i
; } do { int x
; dg
= { ++x
; }; } // -> closure [local] appears
882 override void bar5(int i
) out { B9383
.val
= i
; } do { dg
= { ++i
; }; } // -> closure [parameter] appears
883 override void bar6(int i
) out { B9383
.val
= i
; } do { } // -> closure [local] disappears
884 override void bar7(int i
) out { B9383
.val
= i
; } do { } // -> closure [parameter] disappears
889 auto a
= new A9383();
890 auto b
= new B9383();
892 // base class in-contract is used from derived class. // base derived
893 b
.foo1(101); assert(A9383
.val
== 101 && B9383
.val
== 101); // no closure -> no closure
894 b
.foo2(102); assert(A9383
.val
== 102 && B9383
.val
== 102); // closure [local] -> closure [local] appears
895 b
.foo3(103); assert(A9383
.val
== 103 && B9383
.val
== 103); // closure [parameter] -> closure [parameter]
896 b
.foo4(104); assert(A9383
.val
== 104 && B9383
.val
== 104); // no closure -> closure [local] appears
897 b
.foo5(105); assert(A9383
.val
== 105 && B9383
.val
== 105); // no closure -> closure [parameter] appears
898 b
.foo6(106); assert(A9383
.val
== 106 && B9383
.val
== 106); // closure [local] -> closure [local] disappears
899 b
.foo7(107); assert(A9383
.val
== 107 && B9383
.val
== 107); // closure [parameter] -> closure [parameter] disappears
901 // base class out-contract is used from derived class. // base derived
902 b
.bar1(101); assert(A9383
.val
== 101 && B9383
.val
== 101); // no closure -> no closure
903 b
.bar2(102); assert(A9383
.val
== 102 && B9383
.val
== 102); // closure [local] -> closure [local] appears
904 b
.bar3(103); assert(A9383
.val
== 103 && B9383
.val
== 103); // closure [parameter] -> closure [parameter]
905 b
.bar4(104); assert(A9383
.val
== 104 && B9383
.val
== 104); // no closure -> closure [local] appears
906 b
.bar5(105); assert(A9383
.val
== 105 && B9383
.val
== 105); // no closure -> closure [parameter] appears
907 b
.bar6(106); assert(A9383
.val
== 106 && B9383
.val
== 106); // closure [local] -> closure [local] disappears
908 b
.bar7(107); assert(A9383
.val
== 107 && B9383
.val
== 107); // closure [parameter] -> closure [parameter] disappears
910 // in-contract in base class.
911 a
.foo1(101); assert(A9383
.val
== 101); // no closure
912 a
.foo2(102); assert(A9383
.val
== 102); // closure [local]
913 a
.foo3(103); assert(A9383
.val
== 103); // closure [parameter]
915 // out-contract in base class.
916 a
.bar1(101); assert(A9383
.val
== 101); // no closure
917 a
.bar2(102); assert(A9383
.val
== 102); // closure [local]
918 a
.bar3(103); assert(A9383
.val
== 103); // closure [parameter]
921 /*******************************************/
922 // https://issues.dlang.org/show_bug.cgi?id=15524
923 // Different from https://issues.dlang.org/show_bug.cgi?id=9383 cases, closed variable size is bigger than REGSIZE.
927 static void delegate() dg
;
930 void failInBase() { assert(typeid(this) is typeid(A15524
)); }
933 void foo1(string s
) in { A15524
.val
= s
; failInBase
; } do { } // no closure
934 void foo2(string s
) in { A15524
.val
= s
; failInBase
; } do { string x
; dg
= { x
= null; }; } // closure [local]
935 void foo3(string s
) in { A15524
.val
= s
; failInBase
; } do { dg
= { s
= null; }; } // closure [parameter]
936 void foo4(string s
) in { A15524
.val
= s
; failInBase
; } do { } // no closure
937 void foo5(string s
) in { A15524
.val
= s
; failInBase
; } do { } // no closure
938 void foo6(string s
) in { A15524
.val
= s
; failInBase
; } do { string x
; dg
= { x
= null; }; } // closure [local]
939 void foo7(string s
) in { A15524
.val
= s
; failInBase
; } do { dg
= { s
= null; }; } // closure [parameter]
941 // out-contract tests
942 void bar1(string s
) out { A15524
.val
= s
; } do { } // no closure
943 void bar2(string s
) out { A15524
.val
= s
; } do { string x
; dg
= { x
= null; }; } // closure [local]
944 void bar3(string s
) out { A15524
.val
= s
; } do { dg
= { s
= null; }; } // closure [parameter]
945 void bar4(string s
) out { A15524
.val
= s
; } do { } // no closure
946 void bar5(string s
) out { A15524
.val
= s
; } do { } // no closure
947 void bar6(string s
) out { A15524
.val
= s
; } do { string x
; dg
= { x
= null; }; } // closure [local]
948 void bar7(string s
) out { A15524
.val
= s
; } do { dg
= { s
= null; }; } // closure [parameter]
951 class B15524
: A15524
956 override void foo1(string s
) in { B15524
.val
= s
; } do { } // -> no closure
957 override void foo2(string s
) in { B15524
.val
= s
; } do { string x
; dg
= { x
= null; }; } // -> closure [local] appears
958 override void foo3(string s
) in { B15524
.val
= s
; } do { dg
= { s
= null; }; } // -> closure [parameter]
959 override void foo4(string s
) in { B15524
.val
= s
; } do { string x
; dg
= { x
= null; }; } // -> closure [local] appears
960 override void foo5(string s
) in { B15524
.val
= s
; } do { dg
= { s
= null; }; } // -> closure [parameter] appears
961 override void foo6(string s
) in { B15524
.val
= s
; } do { } // -> closure [local] disappears
962 override void foo7(string s
) in { B15524
.val
= s
; } do { } // -> closure [parameter] disappears
964 // out-contract tests
965 override void bar1(string s
) out { B15524
.val
= s
; } do { } // -> no closure
966 override void bar2(string s
) out { B15524
.val
= s
; } do { string x
; dg
= { x
= null; }; } // -> closure [local] appears
967 override void bar3(string s
) out { B15524
.val
= s
; } do { dg
= { s
= null; }; } // -> closure [parameter]
968 override void bar4(string s
) out { B15524
.val
= s
; } do { string x
; dg
= { x
= null; }; } // -> closure [local] appears
969 override void bar5(string s
) out { B15524
.val
= s
; } do { dg
= { s
= null; }; } // -> closure [parameter] appears
970 override void bar6(string s
) out { B15524
.val
= s
; } do { } // -> closure [local] disappears
971 override void bar7(string s
) out { B15524
.val
= s
; } do { } // -> closure [parameter] disappears
976 auto a
= new A15524();
977 auto b
= new B15524();
979 // base class in-contract is used from derived class. // base derived
980 b
.foo1("1"); assert(A15524
.val
== "1" && B15524
.val
== "1"); // no closure -> no closure
981 b
.foo2("2"); assert(A15524
.val
== "2" && B15524
.val
== "2"); // closure [local] -> closure [local] appears
982 b
.foo3("3"); assert(A15524
.val
== "3" && B15524
.val
== "3"); // closure [parameter] -> closure [parameter]
983 b
.foo4("4"); assert(A15524
.val
== "4" && B15524
.val
== "4"); // no closure -> closure [local] appears
984 b
.foo5("5"); assert(A15524
.val
== "5" && B15524
.val
== "5"); // no closure -> closure [parameter] appears
985 b
.foo6("6"); assert(A15524
.val
== "6" && B15524
.val
== "6"); // closure [local] -> closure [local] disappears
986 b
.foo7("7"); assert(A15524
.val
== "7" && B15524
.val
== "7"); // closure [parameter] -> closure [parameter] disappears
988 // base class out-contract is used from derived class. // base derived
989 b
.bar1("1"); assert(A15524
.val
== "1" && B15524
.val
== "1"); // no closure -> no closure
990 b
.bar2("2"); assert(A15524
.val
== "2" && B15524
.val
== "2"); // closure [local] -> closure [local] appears
991 b
.bar3("3"); assert(A15524
.val
== "3" && B15524
.val
== "3"); // closure [parameter] -> closure [parameter]
992 b
.bar4("4"); assert(A15524
.val
== "4" && B15524
.val
== "4"); // no closure -> closure [local] appears
993 b
.bar5("5"); assert(A15524
.val
== "5" && B15524
.val
== "5"); // no closure -> closure [parameter] appears
994 b
.bar6("6"); assert(A15524
.val
== "6" && B15524
.val
== "6"); // closure [local] -> closure [local] disappears
995 b
.bar7("7"); assert(A15524
.val
== "7" && B15524
.val
== "7"); // closure [parameter] -> closure [parameter] disappears
997 // in-contract in base class.
998 a
.foo1("1"); assert(A15524
.val
== "1"); // no closure
999 a
.foo2("2"); assert(A15524
.val
== "2"); // closure [local]
1000 a
.foo3("3"); assert(A15524
.val
== "3"); // closure [parameter]
1002 // out-contract in base class.
1003 a
.bar1("1"); assert(A15524
.val
== "1"); // no closure
1004 a
.bar2("2"); assert(A15524
.val
== "2"); // closure [local]
1005 a
.bar3("3"); assert(A15524
.val
== "3"); // closure [parameter]
1010 auto t1
= new Test15524a();
1011 t1
.infos
["first"] = 0; //t1.add("first");
1014 auto t2
= new Test15524b();
1022 void add(string key
)
1025 assert(key
!in infos
); // @@@ crash here at second
1029 auto item
= new class
1034 // affects, key parameter is made a closure variable.
1042 void add(string key
)
1045 assert(key
== "second"); // @@@ fails
1049 static void delegate() dg
;
1050 dg
= { auto x
= key
; };
1051 // affects, key parameter is made a closure variable.
1055 /*******************************************/
1056 // https://issues.dlang.org/show_bug.cgi?id=10479
1061 out { } do { return null; }
1064 class D10479
: B10479
1066 override D10479
foo() { return null; }
1069 /*******************************************/
1070 // https://issues.dlang.org/show_bug.cgi?id=10596
1079 /*******************************************/
1080 // https://issues.dlang.org/show_bug.cgi?id=10721
1100 /*******************************************/
1101 // https://issues.dlang.org/show_bug.cgi?id=10981
1105 void foo(int i
) pure
1111 /*******************************************/
1112 // https://issues.dlang.org/show_bug.cgi?id=14779
1116 final void foo(int v
)
1117 in { assert(v
== 0); }
1118 out { assert(v
== 0); }
1126 auto c
= new C14779();
1130 /*******************************************/
1131 // https://issues.dlang.org/show_bug.cgi?id=15984
1136 void check15984(T
)(const char* s
, T this_
, int i
)
1138 printf("%s this = %p, i = %d\n", s
, this_
, i
);
1139 static if (is(T
== I15984
)) assert(this_
is i15984
);
1140 else static if (is(T
== C15984
)) assert(this_
is c15984
);
1141 else static assert(0);
1148 in { check15984("I.f1.i", this, i
); assert(0); }
1149 out { check15984("I.f1.o", this, i
); }
1152 in { check15984("I.f2.i", this, i
); assert(0); }
1153 out { check15984("I.f2.o", this, i
); }
1156 in { void nested() { check15984("I.f3.i", this, i
); } nested(); assert(0); }
1157 out { void nested() { check15984("I.f3.o", this, i
); } nested(); }
1159 void f4(out int i
, lazy int j
)
1164 class C15984
: I15984
1167 in { check15984("C.f1.i", this, i
); }
1168 out { check15984("C.f1.o", this, i
); }
1169 do { check15984("C.f1 ", this, i
); }
1172 in { check15984("C.f2.i", this, i
); }
1173 out { check15984("C.f2.o", this, i
); }
1174 do { check15984("C.f2 ", this, i
); return [0,0,0]; }
1177 in { void nested() { check15984("C.f3.i", this, i
); } nested(); }
1178 out { void nested() { check15984("C.f3.o", this, i
); } nested(); }
1179 do { check15984("C.f3 ", this, i
); }
1181 void f4(out int i
, lazy int j
)
1188 c15984
= new C15984
;
1190 printf("i = %p\n", i15984
);
1191 printf("c = %p\n", c15984
);
1203 /*******************************************/
1205 //******************************************/
1208 int dip1009_1(int x
)
1209 in (x
> 0, "x must be positive!")
1210 out (r
; r
< 0, "r must be negative!")
1211 in (true, "cover trailing comma case",)
1212 out (; true, "cover trailing comma case",)
1217 int dip1009_2(int x
)
1224 int dip1009_3(int x
)
1232 void dip1009_4(int x
)
1241 void dip1009_5(int x
)
1246 int dip1009_6(int x
, int y
)
1257 int dip1009_7(int x
)
1259 in { assert(x
> 1); }
1260 out { assert(x
> 2); }
1271 invariant (x
> 0, "x must stay positive");
1272 invariant (x
> 1, "x must be greater than one",);
1275 void foo(){ x
= 5; }
1278 /*******************************************/
1310 new DIP1009_8().foo();
1312 printf("Success\n");