www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11303] New: IsExpression can not return the correct result about function & delegate

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

           Summary: IsExpression can not return the correct result about
                    function & delegate
           Product: D
           Version: D2
          Platform: All
        OS/Version: Windows
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: 786325481 QQ.com


--- Comment #0 from Xuchong <786325481 QQ.com> 2013-10-19 23:24:48 PDT ---
Sorry for my poor English.

I find that IsExpression can not return the correct result about function &
delegate.

Sample like that:

unittest
{
    static int test(int x)
    {
        return x * 2;
    }

    auto fn1 = &test;
    auto fn2 = (int x) { return x * 2; };
    auto fn3 = (int x) { return x * 2; };
    auto fn4 = (int x) => x * 2;
    auto fn5 = function (int x) => x * 2;
    auto fn6 = function (int x) { return x * 2; };

    static assert(is(typeof(fn1) == function));
    static assert(is(typeof(fn2) == function));
    static assert(is(typeof(fn3) == function));
    static assert(is(typeof(fn4) == function));
    static assert(is(typeof(fn5) == function));
    static assert(is(typeof(fn6) == function));
}

IsExpression always return false, but the correct result is true.

My environment :

OS : Win8.1 Preview x64
Compiler: dmd2 2.063.2 & dmd2 2.064 beta
IDE : Mono-D

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


Max Samukha <samukha voliacable.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |samukha voliacable.com
         Resolution|                            |INVALID


--- Comment #1 from Max Samukha <samukha voliacable.com> 2013-10-20 01:18:01
PDT ---
is(T == function) tests for function object type, not function pointer type.
Many consider that an inconsistency, but that's the state of things. Your tests
should be:

   static assert(is(typeof(*fn1) == function));
   static assert(is(typeof(*fn2) == function));
   static assert(is(typeof(*fn3) == function));
   static assert(is(typeof(*fn4) == function));
   static assert(is(typeof(*fn5) == function));
   static assert(is(typeof(*fn6) == function));

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



--- Comment #2 from Xuchong <786325481 QQ.com> 2013-10-20 05:20:26 PDT ---
(In reply to comment #1)
 is(T == function) tests for function object type, not function pointer type.
 Many consider that an inconsistency, but that's the state of things. Your tests
 should be:
 
    static assert(is(typeof(*fn1) == function));
    static assert(is(typeof(*fn2) == function));
    static assert(is(typeof(*fn3) == function));
    static assert(is(typeof(*fn4) == function));
    static assert(is(typeof(*fn5) == function));
    static assert(is(typeof(*fn6) == function));
Ohhhhhhhh... I got it. Thanks for your reply. I am reading the TDPL.In the last paragraph of Chapter 5.6,there is a little example code.It likes that: auto f = (int i) {}; assert(is(f == function)); So I write the tests above. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 20 2013