D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 9383 - Wrong context for contracts if closure [dis]appears in override function
Summary: Wrong context for contracts if closure [dis]appears in override function
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 major
Assignee: No Owner
URL:
Keywords: contracts, pull, wrong-code
: 9897 13339 (view as issue list)
Depends on:
Blocks:
 
Reported: 2013-01-24 00:24 UTC by Denis Shelomovskii
Modified: 2017-07-22 12:35 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Denis Shelomovskii 2013-01-24 00:24:55 UTC
---
import std.stdio;

void delegate() del;

abstract class A
{
    void f(int i)
    in { writeln("A.f.in: i = ", i); }
    body { } // no closure 

    void g(int i)
    in { writeln("A.g.in: i = ", i); }
    body { int x; del = { ++x; }; } // closure 
}

final class B: A
{
    override void f(int i)
    in { writeln("B.f.in: i = ", i); }
    body { int x; del = { ++x; }; } // closure appears

    override void g(int i)
    in { writeln("B.g.in: i = ", i); }
    body { } // closure disappears
}

void main()
{
    auto b = new B();
    b.f(107);
    b.g(108);
}
---

Output:
---
A.f.in: i = 909192741
A.g.in: i = 10428304
---

Also see Issue 6417.
Comment 2 Kenji Hara 2015-07-01 07:44:35 UTC
*** Issue 13339 has been marked as a duplicate of this issue. ***
Comment 3 Kenji Hara 2015-07-01 08:03:00 UTC
*** Issue 9897 has been marked as a duplicate of this issue. ***
Comment 4 github-bugzilla 2015-07-06 20:38:22 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/47d9320e73b7fc6e95ef6bb9d9b571ab8a4548d8
fix Issue 9383 - Wrong context for contracts if closure [dis]appears in override function

https://github.com/D-Programming-Language/dmd/commit/8e8781489d7fdcfe486020644ed31b2f8d774d8e
Merge pull request #4788 from 9rnsr/fix9383

Issue 9383 - Wrong context for contracts if closure [dis]appears in override function
Comment 5 github-bugzilla 2017-07-22 12:35:59 UTC
Commits pushed to dmd-cxx at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/47d9320e73b7fc6e95ef6bb9d9b571ab8a4548d8
fix Issue 9383 - Wrong context for contracts if closure [dis]appears in override function

https://github.com/dlang/dmd/commit/8e8781489d7fdcfe486020644ed31b2f8d774d8e
Merge pull request #4788 from 9rnsr/fix9383