www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7585] New: functions in templates inferred as delegate

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7585

           Summary: functions in templates inferred as delegate
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: simendsjo gmail.com



extern(C) alias void function() Callback;

template Wrap(alias dg)
{
    extern(C) void Wrap()
    {
        dg();
    }
}

void main()
{
    Callback cb = &Wrap!( () {} );
}

Error: cannot implicitly convert expression (&Wrap) of type void delegate()
pure nothrow  safe to extern (C) void function()

According to Timon Gehr: "'() {}' should be inferred as void function()pure
nothrow  safe." http://forum.dlang.org/post/jib1a2$1jl5$1 digitalmars.com

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 25 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7585




The root cause is conservative escape analysis for nested template
instantiation.

extern(C) alias void function() Callback;

template Wrap(alias dg)
{
    extern(C) void Wrap() { dg(); }
}

void f1(){}

void main()
{
    static void f2(){}
    void f3(){}

    Callback cb1 = &Wrap!(f1);      // OK
    Callback cb2 = &Wrap!(f2);      // OK
    Callback cb3 = &Wrap!(f3);      // NG
    Callback cb3 = &Wrap!((){});    // NG
}

Current implementation always treats lambda literal as nested symbol.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 25 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7585


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull, rejects-valid



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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 26 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7585


Ali Cehreli <acehreli yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |acehreli yahoo.com



I would hate to stop the implementation of a useful feature, but isn't this
against the current spec?

  http://dlang.org/expression.html#FunctionLiteral

"If the keywords function or delegate are omitted, it defaults to being a
delegate."

Ali

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 27 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7585


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg gmx.com



PST ---
TDPL says that it's inferred.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 27 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7585




Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/65fe59384a05de9e59cda85f0de8296d6fc9c478


Issue 7585 - functions in templates inferred as delegate

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 29 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7585




Just a reminder: the spec needs to be updated.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 29 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7585




Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/181fb9cd10cf11f20feb22ee13e305f41f9cbe90
Revert "fix Issue 7585 - functions in templates inferred as delegate"

This reverts commit 182edee285f9c7b8c552e5de3c11636aac154991.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 29 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7585




A new pull to retry fixing:
https://github.com/D-Programming-Language/dmd/pull/982

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 05 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7585




Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/24b83f373e93fc553e42213132adabb992c03405
fix Issue 7585 - functions in templates inferred as delegate

https://github.com/D-Programming-Language/dmd/commit/c66af72bd96110c027db69ea560b6dc3f88b3054


Issue 7585 - functions in templates inferred as delegate

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 12 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7585


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com



13:08:39 PST ---

line which fails is:

Callback cb3 = &Wrap!(f3);      // NG

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 05 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7585


timon.gehr gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED





 line which fails is:
 
 Callback cb3 = &Wrap!(f3);      // NG
It is to be expected that this fails. If the OP sample works, I assume this is fixed. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 05 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7585




13:28:09 PST ---



 line which fails is:
 
 Callback cb3 = &Wrap!(f3);      // NG
It is to be expected that this fails. If the OP sample works, I assume this is fixed.
I guess he also expects this to fail then: Callback cb3 = &Wrap!((){}); // NG but it doesn't fail. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 05 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7585








 line which fails is:
 
 Callback cb3 = &Wrap!(f3);      // NG
It is to be expected that this fails. If the OP sample works, I assume this is fixed.
I guess he also expects this to fail then: Callback cb3 = &Wrap!((){}); // NG but it doesn't fail.
This should work. What he wanted to show is that (){ } currently behaves like f3, while it should behave like f1 or f2. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 05 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7585




---


 line which fails is:
 
 Callback cb3 = &Wrap!(f3);      // NG
    Callback cb1 = &Wrap!(f1);      // OK
    Callback cb2 = &Wrap!(f2);      // OK
The Wrap function inside Wrap template is declared with extern(C). So it cannot have any hidden context pointer. And, calling f1 or f2 will not need such extra pointer, then Wrap!(f1) and Wrap!(f2) will succeed to compile.
    Callback cb3 = &Wrap!(f3);      // NG
f3 is a nested function. So the Wrap function should get a hidden context to main function, but it is impossible. Then the instantiation Wrap!(f3) will fail.
    Callback cb3 = &Wrap!((){});    // NG
This should be compiled. The lambda function (){} has no outer context access, so it should not be treated as nested. But, it had been accidentally done. As a conclusion, current compiler works as expected. This bug is already fixed. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 05 2013