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



--- Comment #11 from yebblies <yebbl...@gmail.com> 2012-02-05 01:29:46 EST ---
(In reply to comment #10)
> cast(T[]) [] is a T[], simple as that.  So the bug is that, in this situation,
> for some perverted reason an implicit conversion match is chosen over an exact
> match.  Removing the implicit conversions stops this bug from biting, but I 
> can
> imagine there being other places where it might still be an issue.
> 
> I'm finding it puzzling that changing a method in ArrayLiteralExp would alter
> the implicit conversions of a CastExpression.  But if it works, so be it.

Yes and no.

In CatAssignExp::semantic, the compiler calls implicitConvTo on e2 (the array
literal) to see if it can convert to T[][].  ArrayLiteralExp::implicitConvTo
returns a match level, and unless it returns MATCHnomatch the compiler
essentially rewrites the expression as (e1 ~= cast(typeof(e1))e2).

All that works fine, the problem is in ArrayLiteralExp::implicitConvTo.
An array literal can implicitly convert to a type if the type is an array, and
each element converts to the type's element type.

ArrayLiteralExp::implicitConvTo does that with something like the following
(simplified):

{
level = assume perfect match
foreach(element)
   if conversion match is worse than level
       level = this match
}

Which results in the assumption never being corrected if the literal has zero
elements, which makes sense because an untyped empty array literal converts to
anything.

This breaks down if the array literal has been set an explicit type, which is
what my patch fixes.

The way it's all done is actually quite clever, but it takes a bit of work to
understand.

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

Reply via email to