www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2359] New: typeof(this) gives the wrong type in template mixins

reply d-bugmail puremagic.com writes:
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 digitalmars.com
        ReportedBy: leo.dahlmann 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


-- 
Sep 14 2008
next sibling parent mpt <example example.com> writes:
d-bugmail puremagic.com wrote:
 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 digitalmars.com
         ReportedBy: leo.dahlmann 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
 
 

Use extra parenthesis as a workaround: (typeof(this))
Sep 14 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2359





------- Comment #1 from h3r3tic mat.uni.torun.pl  2009-01-16 08:54 -------
Appears to be fixed with DMD 1.039, probably related to
http://d.puremagic.com/issues/show_bug.cgi?id=2527


-- 
Jan 16 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2359


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |clugdbug yahoo.com.au
         Resolution|                            |FIXED




--- Comment #2 from Don <clugdbug yahoo.com.au>  2009-09-04 02:49:13 PDT ---
This works now. Clearly the same as bug 2527.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 04 2009