Bug 8683 – bad type resolution for template property functions
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-09-17T21:00:00Z
Last change time
2014-09-14T14:52:27Z
Assigned to
nobody
Creator
ellery-newcomer
Comments
Comment #0 by ellery-newcomer — 2012-09-17T21:00:30Z
code:
@property int Foo()() {
return 1;
}
@property int Goo() {
return 1;
}
pragma(msg, typeof(Foo));
pragma(msg, typeof(Goo));
void main() {
import std.stdio;
writeln(Foo);
writeln(Goo);
}
should spit out
int
int
does spit out
void
int
when compiled.
prints
1
1
when ran.
Comment #1 by andrej.mitrovich — 2012-10-04T18:59:29Z
Maybe typeof(Foo!()) is required here?
Comment #2 by maxim — 2012-10-05T10:35:47Z
(In reply to comment #0)
>
<skip>
It may or may not be a bug depending on what spec says and it says little about it. Dlang.org template page says that semantic analysis is done after template instantiation and in your case it is not instantiated. On the one hand, it is obvious that return type does not vary and is always int. On the other hand, dmd is not obligated to do so until full template instantiation.
TDPL p.139-140 says that D uses heterogeneous translation which means that int Foo()() is not a compiled function like int Goo(). At p.236 it additionally says that Foo()() is not a type, it's a means to create a type. This means that asking a typeof from something that is not a type is problematic.
The key point here is whether typeof(Foo) should instantiate type or not for templates like Foo. If it should instantiate, then it should correctly parse return type. If not (and it seems that typeof of templates which cannot be easily instantiated as Foo), than typeof should return some invalid type (like void) or just issue error.
Comment #4 by ellery-newcomer — 2012-10-07T17:51:37Z
(In reply to comment #1)
> Maybe typeof(Foo!()) is required here?
That does work, but I don't see why
pragma(msg, typeof(Foo));
should fail while
writeln(Foo);
succeeds.
Comment #5 by yebblies — 2013-11-24T06:13:06Z
Now works.
Comment #6 by k.hara.pg — 2014-09-14T14:52:27Z
*** This issue has been marked as a duplicate of issue 7538 ***