1373 – typeof(func).stringof fails when func has parameters.

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1373 - typeof(func).stringof fails when func has parameters.
Summary: typeof(func).stringof fails when func has parameters.
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
Reported: 2007年07月25日 04:39 UTC by Don
Modified: 2014年02月16日 15:22 UTC (History)
3 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Don 2007年07月25日 04:39:17 UTC
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))()");
}
Comment 1 sa 2007年08月31日 17:55:15 UTC
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.
Comment 2 Stewart Gordon 2007年10月21日 11:08:50 UTC
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.
Comment 3 Don 2007年10月23日 10:49:16 UTC
(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.
Comment 4 Harry Vennik 2010年04月26日 06:20:08 UTC
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.


AltStyle によって変換されたページ (->オリジナル) /