Thread overview
[Issue 8957] New: Closure not recognized when passing type with post-blit as lazy parameter
Nov 03, 2012
David Nadlinger
Nov 05, 2012
Don
Nov 11, 2012
David Nadlinger
Nov 11, 2012
Walter Bright
Apr 06, 2013
Iain Buclaw
Apr 06, 2013
Walter Bright
Apr 06, 2013
Iain Buclaw
November 03, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8957

           Summary: Closure not recognized when passing type with
                    post-blit as lazy parameter
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: code@klickverbot.at


--- Comment #0 from David Nadlinger <code@klickverbot.at> 2012-11-03 07:20:13 PDT ---
This is a follow-up to the thread »Expression::apply, DeclarationExp and a
possible nested context bug« on dmd-internals:
http://forum.dlang.org/thread/CAP9J_HXG8mTtnojU9YwYuSGZp1NQCdY0+7oeHyoQ2WhNR-dAuw@mail.gmail.com

The following test case shows that the problem I brought up there there also leads to wrong-code bugs in DMD (at least I hope it's still the original problem, I simply extended this from the minimal testcase linked in the thread):

---
extern(C) void printf(const char*, ...);

struct HasPostblit {
    this(this) {};
}

struct Foo {
    HasPostblit hp;
    int i;
}

void print(Foo f) {
    printf("%x\n", f.i);
}

auto toDg(E)(lazy E e) {
    return { return e(); };
}

auto getDg() {
    Foo a;
    a.i = 0x1;
    return toDg(print(a));
}

void smashStack() {
    int[1024] dummy = 0xcafebabe;
}

void main() {
    auto d = getDg();
    smashStack();
    d();
}
---

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 05, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8957



--- Comment #1 from Don <clugdbug@yahoo.com.au> 2012-11-05 00:50:41 PST ---
Quite likely to be related to at least one of the other closure bugs: bug 1841, bug 1759, bug 2148, bug 6141.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 11, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8957



--- Comment #2 from David Nadlinger <code@klickverbot.at> 2012-11-11 13:59:18 PST ---
@Don: For an analysis of why this happens and a minimal test case, see the linked dmd-internals thread (I'm fairly sure that it is correct, having spent quite some time tracking down the issue in LDC). As to whether this is related to the other bugs, I'm not sure OTOH if an intermediary DeclarationExp is also generated for them.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 11, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8957


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com
           Severity|normal                      |major


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 06, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=8957


Iain Buclaw <ibuclaw@ubuntu.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ibuclaw@ubuntu.com


--- Comment #3 from Iain Buclaw <ibuclaw@ubuntu.com> 2013-04-06 11:25:53 PDT ---
Partial fix.

https://github.com/D-Programming-Language/dmd/pull/1854

What changes is that 'Foo a' is now added to closureVars for the function
getDg().

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 06, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=8957



--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> 2013-04-06 13:04:05 PDT ---
(In reply to comment #3)
> Partial fix.

What is left undone?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 06, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=8957



--- Comment #5 from github-bugzilla@puremagic.com 2013-04-06 13:05:09 PDT ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/bea22e33b11ac8efd07081f43fac1d54d2a9aab2 Merge pull request #1854 from ibuclaw/issue8957

Check declaration initializer expressions for nested refs.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 06, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=8957



--- Comment #6 from Iain Buclaw <ibuclaw@ubuntu.com> 2013-04-06 16:14:57 PDT ---
(In reply to comment #4)
> (In reply to comment #3)
> > Partial fix.
> 
> What is left undone?

Detection in FuncDeclaration:: needsClosure.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------