Bug 271 – Incorrect constant evaluation of TypeInfo equality comparisons
Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P1
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-07-29T13:12:00Z
Last change time
2014-02-15T13:19:33Z
Keywords
wrong-code
Assigned to
bugzilla
Creator
bruno.do.medeiros+deebugz
Comments
Comment #0 by bruno.do.medeiros+deebugz — 2006-07-29T13:12:09Z
Consider:
writefln( typeid(int) is typeid(int) ); // prints true (Correct)
writefln( typeid(int) !is typeid(int) ); // prints false (Correct)
writefln( typeid(int) == typeid(Object) ); // prints 0 (Correct)
writefln( typeid(int) != typeid(Object) ); // prints false! (Correct)
// prints true (INCORRECT), should be 1, an int:
writefln( typeid(int) == typeid(int) );
// prints true (INCORRECT), should be false:
writefln( typeid(int) != typeid(int) );
// prints bool (INCORRECT), should be int
writefln( typeid(typeof(typeid(int) == typeid(int))) );
The bug is in the constant folding(evaluation) system: if we the check the asm for that code then 1(true) is generated for both == and != calls. Also, the following code, which are all runtime evaluations, work correctly:
auto ti = typeid(int);
writefln( ti == ti ); // prints 1 (Correct)
writefln( ti != ti ); // prints false (Correct)
writefln( ti == typeid(int) ); // prints 1 (Correct)
writefln( ti != typeid(int) ); // prints false (Correct)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Bruno Medeiros schrieb am 2006-08-14:
> Thomas Kuehne wrote:
>> http://dstress.kuehne.cn/run/t/typeid_90_G.d
for reference the test was:
#
# assert(typeid(typeof(typeid(int) == typeid(int))).toString()
# == typeid(typeof(args[0].length == args.length)).toString());
#
> I don't think this test case is correct. You test the type-of a TypeInfo
> (which is an Object) equality operation vs the type-of an int(which is a
> primitive type) equality operation. Nothing says that such type-of
> should be the same (even though I very much think it should).
>
> What I do think is not correct is the following (second line) :
>
> writefln( typeid(typeof(typeid(int) == typeid(char))) );// int
> writefln( typeid(typeof(typeid(int) == typeid(int))) );//bool INCORRECT?
> writefln( typeid(typeof(new Object == new Object)) ); // int
>
> writefln( typeid(typeof(typeid(int) != typeid(char))) ); // bool
> writefln( typeid(typeof(typeid(int) != typeid(int))) ); // bool
> writefln( typeid(typeof(new Object != new Object)) ); // bool
See new issue tracker:
http://d.puremagic.com/issues/show_bug.cgi?id=288
Thomas
-----BEGIN PGP SIGNATURE-----
iD8DBQFE4cjWLK5blCcjpWoRAqqdAJoD3bFNsF7172YrvL5GmDB9KfBQkACgrNHF
5ltSQGIWN5RhPLUmIXjTNOI=
=f3zJ
-----END PGP SIGNATURE-----