Comment #0 by bearophile_hugs — 2011-07-31T08:55:25Z
D2 code:
import core.stdc.stdio: printf;
import std.algorithm: count;
class Foo {
void bar()
out {
int i = 10;
count!((int k){ printf("%d\n", i); return 1; })([0]);
} body {}
}
void main() {
auto f = new Foo();
f.bar();
}
It prints:
1244668
Instead of:
10
Comment #1 by kennytm — 2011-07-31T15:32:23Z
Reduced test case:
-------------------------------
//import core.stdc.stdio;
class Bug6417 {
void bar()
in {
int i = 14;
assert(i == 14);
auto d = (){
assert(i == 14, "in contract failure"); // <-- fail
};
//printf("%p %p\n", d.ptr, &this);
d();
}
out {
int i = 10;
assert(i == 10);
(){
assert(i == 10, "out contract failure"); // <-- also fail
}();
}
body {}
}
void main() {
(new Bug6417).bar();
}
-------------------------------
When running, the "in contract failure" assertion will be thrown.
Comment #2 by kekeniro2 — 2013-05-24T22:35:37Z
Created attachment 1216
test case for foreach-opApply
I'm also hit this by foreach-block using opApply-range.
The test case is attached.
Comment #3 by verylonglogin.reg — 2014-02-19T07:50:12Z
This is for virtual class member functions only, reduced testcase:
---
final class C
{
void f()
in // or `out`
{
int i = 7;
void g() { assert(i == 7); }
g();
}
body
{ }
}
void main()
{
new C().f();
}
---