Bug 6417 – Wrong context for nested functions in virtual class member function contracts

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-07-31T08:55:00Z
Last change time
2017-07-22T12:35:50Z
Keywords
contracts, pull, wrong-code
Assigned to
nobody
Creator
bearophile_hugs

Attachments

IDFilenameSummaryContent-TypeSize
1216contract_foreach.dtest case for foreach-opApplyapplication/octet-stream623

Comments

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(); } ---
Comment #4 by k.hara.pg — 2015-06-30T12:13:55Z
Comment #5 by k.hara.pg — 2015-07-01T08:06:11Z
*** Issue 6118 has been marked as a duplicate of this issue. ***
Comment #6 by github-bugzilla — 2015-07-05T23:03:50Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/b2f1367b3791a87f440d8531d228071a32ef7f2a fix Issue 6417 - Wrong context for nested functions in virtual class member function contracts https://github.com/D-Programming-Language/dmd/commit/82f91e2db26a0cf9cb09b4d802b7b72d6138673d Merge pull request #4789 from 9rnsr/fix6417 Issue 6417 - Wrong context for nested functions in virtual class member function contracts
Comment #7 by github-bugzilla — 2015-10-04T18:18:55Z
Commits pushed to stable at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/b2f1367b3791a87f440d8531d228071a32ef7f2a fix Issue 6417 - Wrong context for nested functions in virtual class member function contracts https://github.com/D-Programming-Language/dmd/commit/82f91e2db26a0cf9cb09b4d802b7b72d6138673d Merge pull request #4789 from 9rnsr/fix6417
Comment #8 by github-bugzilla — 2017-07-22T12:35:50Z
Commits pushed to dmd-cxx at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/b2f1367b3791a87f440d8531d228071a32ef7f2a fix Issue 6417 - Wrong context for nested functions in virtual class member function contracts https://github.com/dlang/dmd/commit/82f91e2db26a0cf9cb09b4d802b7b72d6138673d Merge pull request #4789 from 9rnsr/fix6417