May 08, 2005
Here's the whole list of problems I've found with the TypeInfo implementation while implementing boxing.

1) TypeInfo_Array is not used properly for types such as typeid(char[]); it can be casted to TypeInfo_Array, but the result is an invalid pointer:

     void main()
     {
         TypeInfo_Array type = cast(TypeInfo_Array) typeid(char[]);

         assert (type !== null);
         assert (type.next !== null);
         printf("next: %.*s\n", type.next.classinfo.name);
     }

This succeeds in the assertions but has an Access Violation in the printf.  Arrays should correctly support TypeInfo_Array, and the classes in "/dmd/src/phobos/std/typeinfo/ti_A*.d" should specify that they inherit from TypeInfo_Array.

Arrays of non-basic-types correctly support TypeInfo_Array.

2) TypeInfo.opEquals uses a simple string check and is not overloaded, which has bad results:

    void main()
    {
        struct A { }
        struct B { }

        assert (typeid(A) != typeid(B));
    }

The assertion test fails; it should succeed.

3) Interfaces cannot be specialized.  Not entirely related to this issue, but a related problem.

     template T (A) { int T = 0; }
     template T (A : Object) { int T = 1; }
     template T (A : Interface) { int T = 1; }

     void main()
     {
         interface I { }
         class A { }

         assert (T!(A));
         assert (T!(I));
     }

This fails in the second assertion test; there should be SOME way to specialize for them.  I was also getting problems with crashing when boxing interfaces, but I can't make a testcase out of it right now.

----

I have attached a replacement for "/dmd/src/phobos/internal/object.d" that overloads opEquals for the TypeInfo sub-types as well as ClassInfo, and it includes fixes for the TypeInfo_A* types, although the compiler still generates these objects incorrectly.  This preserves its proper handling of DLLs while also making it work properly in most instances; the exceptions are that these assertions fail when they should succeed:

    assert(typeid(int function(float)) != typeid(int function(char)));
    assert(typeid(int delegate(float)) != typeid(int delegate(char)));

This also fails with my code:

    [module A]
    class Class { }

    [module B]
    class Class { }

    [module C]
    import A, B;

    void main()
    {
        A.Class a = new A.Class;
        B.Class b = new B.Class;
        assert(a.classinfo != b.classinfo);
    }

This is because ClassInfo.name does not contain the full module name, unlike TypeInfo_Struct, so ClassInfo.opEquals can be ambiguous.


May 14, 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Burton Radons schrieb am Sun, 08 May 2005 12:22:18 -0700:
> Here's the whole list of problems I've found with the TypeInfo implementation while implementing boxing.
>
> 1) TypeInfo_Array is not used properly for types such as typeid(char[]); it can be casted to TypeInfo_Array, but the result is an invalid pointer:
>
>      void main()
>      {
>          TypeInfo_Array type = cast(TypeInfo_Array) typeid(char[]);
>
>          assert (type !== null);
>          assert (type.next !== null);
>          printf("next: %.*s\n", type.next.classinfo.name);
>      }
>
> This succeeds in the assertions but has an Access Violation in the printf.  Arrays should correctly support TypeInfo_Array, and the classes in "/dmd/src/phobos/std/typeinfo/ti_A*.d" should specify that they inherit from TypeInfo_Array.
>
> Arrays of non-basic-types correctly support TypeInfo_Array.

Updated existing typeid test cases.

> 2) TypeInfo.opEquals uses a simple string check and is not overloaded, which has bad results:
>
>     void main()
>     {
>         struct A { }
>         struct B { }
>
>         assert (typeid(A) != typeid(B));
>     }
>
> The assertion test fails; it should succeed.

Added to DStress as http://dstress.kuehne.cn/run/t/typeid_86_A.d http://dstress.kuehne.cn/run/t/typeid_86_B.d http://dstress.kuehne.cn/run/t/typeid_86_C.d http://dstress.kuehne.cn/run/t/typeid_86_D.d http://dstress.kuehne.cn/run/t/typeid_86_D.d

> This also fails with my code:
>
>     [module A]
>     class Class { }
>
>     [module B]
>     class Class { }
>
>     [module C]
>     import A, B;
>
>     void main()
>     {
>         A.Class a = new A.Class;
>         B.Class b = new B.Class;
>         assert(a.classinfo != b.classinfo);
>     }
>
> This is because ClassInfo.name does not contain the full module name, unlike TypeInfo_Struct, so ClassInfo.opEquals can be ambiguous.

Updated existing typeid test cases.

Thomas


-----BEGIN PGP SIGNATURE-----

iD8DBQFChbwS3w+/yD4P9tIRAqmlAJ9Id9jj5bUWQTC0faDGu08jjUcL+QCgxHeN
OdD5C49TxMY/+akjK68vAmI=
=TC2z
-----END PGP SIGNATURE-----