Thread overview
[Issue 3086] New: TypeInfo opEquals returns incorrect results
Jun 22, 2009
nfxjfg@gmail.com
Jun 08, 2010
nfxjfg@gmail.com
Jun 08, 2010
nfxjfg@gmail.com
Jan 07, 2011
nfxjfg@gmail.com
Jan 07, 2011
Brad Roberts
Apr 06, 2011
Walter Bright
June 22, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3086

           Summary: TypeInfo opEquals returns incorrect results
           Product: D
           Version: 1.045
          Platform: x86
        OS/Version: Linux
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: nfxjfg@gmail.com


If a and b are TypeInfo, a==b can return true, even if a and b refer to different types (and object instances). Both Phobos and Tango are affected.

The code example at the end of this report demonstrates this. The second assertion fails, because opEquals() returns true when comparing two different TypeInfos. This is because opEquals compares the two TypeInfo by their toString() results. The returnd string doesn't contain any information about the delegate parameters, ths delegates with the same return type are considered equal.

I wonder if TypeInfo.opEquals() shouldn't only compare the addresses of the TypeInfo objects. The string comparision seems pointless, even if you use DLLs. With DLLs, you should either not attempt to use objects from another instance of the runtime, or you should use proper solutions like DDL, which enables to DLLs to share the same runtime. The string comparision hack is hard to get right, because the compiler needs just another method to encode the complete information about a type as string. (A better hack would be to compare the mangled symbol names.)



//program will execute successfully if bug is fixed

class X {
    void a() {}
    void b(int z, short c) {}
}

void main() {
    auto z = new X();
    TypeInfo a = typeid(typeof(&z.a));
    TypeInfo b = typeid(typeof(&z.b));
    //doesn't fail (ok)
    assert(a !is b, "1");
    //fails (which is wrong, because both TypeInfos are different!)
    assert(a != b, "2");
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 08, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3086


nfxjfg@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code


--- Comment #1 from nfxjfg@gmail.com 2010-06-07 20:18:41 PDT ---
Attributes such as pure are also ignored.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 08, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3086


nfxjfg@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #2 from nfxjfg@gmail.com 2010-06-07 20:20:14 PDT ---
*** Issue 3831 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 07, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3086


nfxjfg@gmail.com changed:

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


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 07, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3086


Brad Roberts <braddr@puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |braddr@puremagic.com
         Resolution|WONTFIX                     |


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 06, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3086


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> 2011-04-05 20:38:27 PDT ---
Fixing this in D1 will produce some binary incompatibilities, so I'm going to just do a partial fix for it. Fixed for D2.

https://github.com/D-Programming-Language/dmd/commit/27d23cf8952471d0023331a719174e0823a3a9fc

https://github.com/D-Programming-Language/dmd/commit/cebc2fc0b3cf947372dd83f5c7b30f6a2c467799

https://github.com/D-Programming-Language/phobos/commit/4fe5c5c760af2ef0f61429bf0b9c128c2a663f9a

https://github.com/D-Programming-Language/druntime/commit/a6c5d0c6fdc1b71c074e5cb3432597e99fb46a5f

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------