[Issue 2359] New: typeof(this) gives the wrong type in template mixins
mpt
example at example.com
Sun Sep 14 12:20:11 PDT 2008
d-bugmail at 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 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
>
>
Use extra parenthesis as a workaround:
(typeof(this))
More information about the Digitalmars-d-bugs
mailing list