http://d.puremagic.com/issues/show_bug.cgi?id=2954


Don <clugd...@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |clugd...@yahoo.com.au


--- Comment #3 from Don <clugd...@yahoo.com.au> 2010-11-16 01:10:11 PST ---
The fix for bug 2684 was incorrect; it was too general. We can't skip the
implicit conversion in all cases where the arrays are equality comparable.

For example, this code:

    char[char[3]] ac;
    dchar[3] d = "abc"d;
    ac[d] = 'w';
gives a poor error message:
bug.d(6): Error: array equality comparison type mismatch, dchar[3u] vs char
[3u]
instead of "cannot implicitly convert"

PATCH: 
(1) Add this function to cast.c

/***********************************
 * See if both types are arrays that can be compared
 * for equality without any casting. Return !=0 if so.
 * This is to enable comparing things like an immutable
 * array with a mutable one.
 */
int arrayTypeCompatibleWithoutCasting(Loc loc, Type *t1, Type *t2)
{
    t1 = t1->toBasetype();
    t2 = t2->toBasetype();

    if ((t1->ty == Tarray || t1->ty == Tsarray || t1->ty == Tpointer) &&
        t2->ty == t1->ty)
    {
        if (t1->nextOf()->implicitConvTo(t2->nextOf()) >= MATCHconst ||
            t2->nextOf()->implicitConvTo(t1->nextOf()) >= MATCHconst)
            return 1;
    }
    return 0;
}

(2) expression.c line 8580

        case Taarray:
        {   TypeAArray *taa = (TypeAArray *)t1;
+            /* We can skip the implicit conversion if they differ only by
+             * constness (Bugzilla 2684, see also bug 2954b)
+             */
+            if (!arrayTypeCompatibleWithoutCasting(e2->loc, e2->type,
taa->index) )
-            if (!arrayTypeCompatible(e2->loc, e2->type, taa->index))
            {
                e2 = e2->implicitCastTo(sc, taa->index);        // type
checking
            }
            type = taa->next;

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

Reply via email to