www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1373] New: typeof(func).stringof fails when func has parameters.

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

           Summary: typeof(func).stringof   fails when func has parameters.
           Product: D
           Version: 1.019
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: clugdbug yahoo.com.au


If func is a function (not a function pointer) with zero arguments, it works
correctly (I think). But if it is a function with >0 arguments, then it
complains that it cannot evaluate it.

Curiously, it generates the correct result, as evidenced by pragma(msg) below,
before giving the error.

--------------
double func0() { return 0; }
int func2(int a, int b) { return 2; }

void main()
{  
    static assert(typeof(func0).stringof=="(double())()"); // OK
    pragma(msg, typeof(func2).stringof);
    // bug.d(8): Error: expected 2 arguments, not 0
    // (int(int a, int b))()
    static assert(typeof(func2).stringof=="(int(int a, int b))()");
}


-- 
Jul 25 2007
next sibling parent Reiner Pope <some address.com> writes:
d-bugmail puremagic.com wrote:
 http://d.puremagic.com/issues/show_bug.cgi?id=1373
 
            Summary: typeof(func).stringof   fails when func has parameters.
            Product: D
            Version: 1.019
           Platform: PC
         OS/Version: Windows
             Status: NEW
           Severity: normal
           Priority: P2
          Component: DMD
         AssignedTo: bugzilla digitalmars.com
         ReportedBy: clugdbug yahoo.com.au
 
 
 If func is a function (not a function pointer) with zero arguments, it works
 correctly (I think). But if it is a function with >0 arguments, then it
 complains that it cannot evaluate it.
 
 Curiously, it generates the correct result, as evidenced by pragma(msg) below,
 before giving the error.
 
 --------------
 double func0() { return 0; }
 int func2(int a, int b) { return 2; }
 
 void main()
 {  
     static assert(typeof(func0).stringof=="(double())()"); // OK
     pragma(msg, typeof(func2).stringof);
     // bug.d(8): Error: expected 2 arguments, not 0
     // (int(int a, int b))()
     static assert(typeof(func2).stringof=="(int(int a, int b))()");
 }
 
 

I think a related issue is void func(int) {} const text = func.stringof; which doesn't compile under 2.003, error message: "func_stringof.func(int) does not match parameter types ()". However, it works if the int parameter is removed.
Aug 31 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1373


smjg iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com




------- Comment #2 from smjg iname.com  2007-10-21 11:08 -------
Please don't blindly quote the entire message when replying.  It's bad enough
on any newsgroup, and when it clutters up Bugzilla, it's even worse.

This issue is puzzling me.  Surely typeof(func0) should be double, since as an
expression, func0 is equivalent to func0().  And typeof(func2) probably
shouldn't compile.


-- 
Oct 21 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1373





------- Comment #3 from clugdbug yahoo.com.au  2007-10-23 10:49 -------
(In reply to comment #2)
 Please don't blindly quote the entire message when replying.  It's bad enough
 on any newsgroup, and when it clutters up Bugzilla, it's even worse.
 
 This issue is puzzling me.  Surely typeof(func0) should be double, since as an
 expression, func0 is equivalent to func0().  And typeof(func2) probably
 shouldn't compile.

Function types _are_ wierd. And not well documented. What is func2 ? It's a symbol of "function type". The only thing you do with it it takes its address. Since in the spec, it's allowable in & UnaryExpression, it must be an expression, but I can't see it listed there. Definitely related to issue #1341. --
Oct 23 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1373


Harry Vennik <htvennik zonnet.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |htvennik zonnet.nl


--- Comment #4 from Harry Vennik <htvennik zonnet.nl> 2010-04-26 06:20:08 PDT
---
This issue bugged me with DMD 2.043 on Mac.

I noticed something peculiar which is demonstrated by this test case:

-----
void foo(int i) { }
enum string FOO_TYPE = typeof(foo).stringof;
pragma(msg, "Type of foo is: " ~ FOO_TYPE);
-----

Compiling that will print:

-----
stringof_error.d(2): Error: expected 1 function arguments, not 0
Type of foo is: (void(int i))()
-----

So actually, the .stringof is correctly evaluated, but still some unnecessary
check for function arguments makes the compiler generate an error.

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