www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - bogus cast errors?

reply "Kris" <fu bar.com> writes:
void main()
{
        char[] s;
        char[] t;

        if (true)
            s = null;
        s = (true) ? null : t;
}

"test.d(8): cannot implicitly convert expression (1 ? null : cast(void*)(t))
of type void* to char[]"

You could be forgiven for thinking the error is talking about 't'. But it's
actually talking about the assignment of null instead. This works as
expected:

s = (true) ? cast(char[]) null : t;

But you've got to explicitly cast the null. Yet, the "more traditional"
assignment, on line 7, is accepted without error. What's the deal here?
Apr 08 2005
next sibling parent "Walter" <newshound digitalmars.com> writes:
Yeah, that ain't right. I'll fix it.
Apr 09 2005
prev sibling parent Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Kris schrieb am Fri, 8 Apr 2005 22:33:34 -0700:
 void main()
 {
         char[] s;
         char[] t;

         if (true)
             s = null;
         s = (true) ? null : t;
 }

 "test.d(8): cannot implicitly convert expression (1 ? null : cast(void*)(t))
 of type void* to char[]"

 You could be forgiven for thinking the error is talking about 't'. But it's
 actually talking about the assignment of null instead. This works as
 expected:

 s = (true) ? cast(char[]) null : t;

 But you've got to explicitly cast the null. Yet, the "more traditional"
 assignment, on line 7, is accepted without error. What's the deal here?
Added to DStress as http://dstress.kuehne.cn/run/cast_25.d http://dstress.kuehne.cn/run/cast_26.d http://dstress.kuehne.cn/run/cast_27.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCV5xW3w+/yD4P9tIRAlafAKCYGMCbyX7qACkUBrK0AHbGZOVn8QCfUn3S B3KhsIqYn8/cBj3jgETW32w= =kslh -----END PGP SIGNATURE-----
Apr 09 2005