Bug 15743 – typeof function literal with unnamed parameter of aliased type is void
Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-03-02T13:59:00Z
Last change time
2016-03-03T02:31:45Z
Assigned to
nobody
Creator
ryan
Comments
Comment #0 by ryan — 2016-03-02T13:59:52Z
alias T = int;
pragma(msg, typeof((string){}).stringof); // void
pragma(msg, typeof((string s){}).stringof); // void function(string)
pragma(msg, typeof((int){}).stringof); // void function(int)
pragma(msg, typeof((T){}).stringof); // void
I would expect the first pragma to print void function(string), and the last to print void function(int).
It appears the issue is with a parameter that has no name _and_ is declared as an aliased type (e.g. if you use immutable(char)* instead of string it works as expected).
Comment #1 by ag0aep6g — 2016-03-02T20:44:16Z
In `(string){}` and `(T){}`, `string` and `T` are actually parameter names, not types. The function literals generate function templates like these:
void foo(A)(A string) {}
void foo(A)(A T) {}
And typeof of a template is void.
The same does not happen with `(int){}` because you can't have a parameter named "int". So it's taken as a type instead.
I'm not sure if there's anything to be fixed/improved here. Maybe function signatures like `void f(int string) {}` should not be allowed ("string" being the name of the parameter here).