[Issue 2359] New: typeof(this) gives the wrong type in template mixins

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Sep 14 04:10:17 PDT 2008


http://d.puremagic.com/issues/show_bug.cgi?id=2359

           Summary: typeof(this) gives the wrong type in template mixins
           Product: D
           Version: 1.035
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: leo.dahlmann at gmail.com


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


-- 



More information about the Digitalmars-d-bugs mailing list