www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 271] New: Incorrect constant evaluation of TypeInfo equality comparisons

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=271

           Summary: Incorrect constant evaluation of TypeInfo equality
                    comparisons
           Product: D
           Version: 0.163
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: critical
          Priority: P1
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: daiphoenix lycos.com


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)


-- 
Jul 29 2006
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=271


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #1 from bugzilla digitalmars.com  2006-08-11 19:19 -------
Fixed DMD 0.164


-- 
Aug 11 2006
prev sibling parent reply Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

d-bugmail puremagic.com schrieb am 2006-07-29:
 http://d.puremagic.com/issues/show_bug.cgi?id=271

 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)

http://dstress.kuehne.cn/run/t/typeid_90_A.d http://dstress.kuehne.cn/run/t/typeid_90_B.d http://dstress.kuehne.cn/run/t/typeid_90_C.d http://dstress.kuehne.cn/run/t/typeid_90_D.d http://dstress.kuehne.cn/run/t/typeid_90_E.d http://dstress.kuehne.cn/run/t/typeid_90_F.d http://dstress.kuehne.cn/run/t/typeid_90_G.d http://dstress.kuehne.cn/run/t/typeid_90_H.d http://dstress.kuehne.cn/run/t/typeid_90_I.d http://dstress.kuehne.cn/run/t/typeid_90_J.d http://dstress.kuehne.cn/run/t/typeid_90_K.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFE4GqFLK5blCcjpWoRAhuqAKCG1Yt42B4A+KNV5Q8ayzS0SpyiLACeL7HJ BbMYlPMUE8k094gkIAip2Nc= =RMHq -----END PGP SIGNATURE-----
Aug 14 2006
parent reply Bruno Medeiros <brunodomedeirosATgmail SPAM.com> writes:
Thomas Kuehne wrote:
 http://dstress.kuehne.cn/run/t/typeid_90_G.d

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 -- Bruno Medeiros - MSc in CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
Aug 14 2006
parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----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-----
Aug 15 2006