www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5359] New: std.traits : isDelegate returns false on a delegate

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

           Summary: std.traits : isDelegate returns false on a delegate
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2010-12-19
14:49:57 PST ---
import std.traits;
import std.stdio : writeln;

void main()
{
    int delegate() dg;

    writeln(typeid(dg));                  // "int delegate()"
    assert(isDelegate!(int delegate()));  // ok

    assert(isSomeFunction!(dg)); // ok..
    assert(isDelegate!(dg));     // fails
}

Huh?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 19 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5359


Jonathan M Davis <jmdavisProg gmx.com> changed:

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


--- Comment #1 from Jonathan M Davis <jmdavisProg gmx.com> 2010-12-19 15:33:16
PST ---
I believe that there are at least a couple of other open bugs on traits and
delegates, so it would appear that traits are very broken for delegates right
now.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 19 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5359


Max Samukha <samukha voliacable.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |samukha voliacable.com


--- Comment #2 from Max Samukha <samukha voliacable.com> 2010-12-20 04:28:28
PST ---
I am sure that using homonym templates for testing types and expressions is a
bad idea. It results in some syntactic compression but at the same time brings
lots of confusion. There should be two distinct templates. Something like this:

template isExpression(alias expression)
{
    enum isExpression = is(typeof(expression));
}

template isDelegate(alias expression) if (isExpression!expression)
{
    enum isDelegate = isDelegateType!(typeof(expression));
}

template isDelegateType(T)
{
    static enum isDelegateType = is(T == delegate);
}

template isFunctionPointer(alias expression) if (isExpression!expression)
{
    enum isFunctionPointer = isFunctionPointerType!(typeof(expression));
}

template isFunctionPointerType(T)
{
    static if (__traits(compiles, *T.init))
        enum isFunctionPointerType = isFunctionType!(typeof((*T.init)));
    else
        enum isFunctionPointerType = false;
}

template isFunctionType(T)
{
    enum isFunctionType = is(T == function);
}

unittest
{
    alias void delegate() Dg;
    Dg dg;
    alias void function() Fn;
    Fn fn;

    static void foo()
    {
    }

    static assert(isDelegate!dg);    
    static assert(isDelegateType!Dg);
    static assert(!__traits(compiles, isDelegate!Dg));
    static assert(!isDelegateType!Fn);    

    static assert(isFunctionPointer!fn);
    static assert(!__traits(compiles, isFunctionPointer!Fn));
    static assert(!isFunctionType!Fn);

    static assert(isFunctionPointerType!Fn);
    static assert(!isFunctionPointerType!Dg);

    static assert(isFunctionType!(typeof(*&foo)));
    static assert(!isFunctionType!Fn);
    static assert(!isFunctionType!Dg);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 20 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5359



--- Comment #3 from Max Samukha <samukha voliacable.com> 2010-12-20 06:02:00
PST ---
"static enum" should be replaced with "enum" in the example

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 20 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5359


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei metalanguage.com
         AssignedTo|nobody puremagic.com        |andrei metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 09 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5359



--- Comment #4 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-02-24
16:24:20 PST ---
The real issue here was that isDelegate should have only accepted types, IOW
this should have been a compile-time error not a runtime one.

Fixed with https://github.com/D-Programming-Language/phobos/pull/1164

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


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #5 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-03-08
13:26:36 PST ---
https://github.com/D-Programming-Language/phobos/pull/1192

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



--- Comment #6 from github-bugzilla puremagic.com 2013-03-09 15:59:05 PST ---
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/091a57650b5cd51cf0912fdee488d5c0730c7e06
Fixes Issue 5359 - isDelegate should work for types and expressions.

https://github.com/D-Programming-Language/phobos/commit/28fad77612f8252658ced4989105271b4f3717a0
Merge pull request #1192 from AndrejMitrovic/Fix5359

Issue 5359 - isDelegate should work for types and expressions.

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


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

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


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