Bug 2359 – typeof(this) gives the wrong type in template mixins
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2008-09-14T06:10:00Z
Last change time
2014-03-01T00:37:00Z
Keywords
wrong-code
Assigned to
nobody
Creator
leo.dahlmann
Comments
Comment #0 by leo.dahlmann — 2008-09-14T06:10:15Z
Code:
---------------
extern(C) int printf(char*, ...);
class A
{
mixin Mix;
}
class B
{
mixin Mix;
}
template Mix()
{
void foo()
{
printf("%.*s\n", typeof(this).classinfo.name);
}
}
void main()
{
(new A).foo();
(new B).foo();
}
---------------
Output with any dmd since 1.032:
main.A
main.A
This shows that typeof(this) in B.foo returns A.
With dmd 1.031 the (imo correct) output is:
main.A
main.B