www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - typedef, implicit cast, bug or feature?

reply Anders Runesson <anders runesson.info> writes:
I'm not sure if this is me missing something, or if it's a bug:

********
import std.stdio;

class BaseClass {
        int BaseProp() { return 1; }
}

typedef BaseClass ClassTypedef;

void testfunc(ClassTypedef t) {    writefln(t.BaseProp());   }
*************

this gives the compiler message:

test.d(9): this for BaseProp needs to be type BaseClass not type
ClassTypedef

The docs say that typedefs can be implicitly cast to their underlying
type, so why can't t be used as a BaseClass reference? Seems like a bug
to me.
/Anders
Jul 16 2006
parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Anders Runesson schrieb am 2006-07-16:
 I'm not sure if this is me missing something, or if it's a bug:

 ********
 import std.stdio;

 class BaseClass {
         int BaseProp() { return 1; }
 }

 typedef BaseClass ClassTypedef;

 void testfunc(ClassTypedef t) {    writefln(t.BaseProp());   }
 *************

 this gives the compiler message:

 test.d(9): this for BaseProp needs to be type BaseClass not type
 ClassTypedef

 The docs say that typedefs can be implicitly cast to their underlying
 type, so why can't t be used as a BaseClass reference? Seems like a bug
 to me.
 /Anders
Added to DStress as http://dstress.kuehne.cn/run/t/typedef_19_A.d http://dstress.kuehne.cn/run/t/typedef_19_B.d http://dstress.kuehne.cn/run/t/typedef_19_C.d http://dstress.kuehne.cn/run/t/typedef_19_D.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFFCQePLK5blCcjpWoRAjOTAJ0Wq+EMvhRz5tVhKPnunjZrJo2hOwCfU2XV UlT5ZGmQvjqjvI0H1nKWG1Y= =8LzP -----END PGP SIGNATURE-----
Sep 14 2006