On 9 October 2011 20:05, Christian Kamm <span dir="ltr"><<a href="mailto:kamm@incasoftware.de">kamm@incasoftware.de</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi!<br>
<br>
I was briefly looking at<br>
<a href="http://d.puremagic.com/issues/show_bug.cgi?id=259" target="_blank">http://d.puremagic.com/issues/show_bug.cgi?id=259</a><br>
today and wondered whether the fix wouldn't be as easy as:<br>
<br>
diff --git a/src/cast.c b/src/cast.c<br>
index c7c78fc..b0c77ee 100644<br>
--- a/src/cast.c<br>
+++ b/src/cast.c<br>
@@ -1629,6 +1629,48 @@ int typeMerge(Scope *sc, Expression *e, Type **pt,<br>
Expression **pe1, Expression<br>
TY ty1 = (TY)Type::impcnvType1[t1b->ty][t2b->ty];<br>
TY ty2 = (TY)Type::impcnvType2[t1b->ty][t2b->ty];<br>
<br>
+ // For compares, don't blindly convert. One range must contain the<br>
other.<br>
+ switch (e->op) {<br>
+ case TOKlt:<br>
+ case TOKle:<br>
+ case TOKgt:<br>
+ case TOKge:<br>
+ case TOKunord:<br>
+ case TOKlg:<br>
+ case TOKleg:<br>
+ case TOKule:<br>
+ case TOKul:<br>
+ case TOKuge:<br>
+ case TOKug:<br>
+ case TOKue: {<br>
+ //printf("\tcompare ranges for comparison\n");<br>
+ IntRange r1 = e1->getIntRange();<br>
+ IntRange r2 = e2->getIntRange();<br>
+ //r1.dump("lhs", e1);<br>
+ //r2.dump("rhs", e2);<br>
+<br>
+ if (IntRange::fromType(t1b).contains(r2)) {<br>
+ //printf("use lhs type\n");<br>
+ t = t1;<br>
+ e2 = e2->castTo(sc, t);<br>
+ goto Lret;<br>
+ }<br>
+ if (IntRange::fromType(t2b).contains(r1)) {<br>
+ //printf("use rhs type\n");<br>
+ t = t2;<br>
+ e1 = e1->castTo(sc, t);<br>
+ goto Lret;<br>
+ }<br>
+<br>
+ //printf("no safe conversion\n");<br>
+ // better error message!<br>
+ goto Lincompatible;<br>
+<br>
+ break;<br>
+ }<br>
+ default: break;<br>
+ }<br>
+<br>
if (t1b->ty == ty1) // if no promotions<br>
{<br>
if (t1 == t2)<br>
<br>
What did I miss? Looking at the first couple of errors when building druntime,<br>
they all seem genuine.<br>
<br>
One thing is probably C code compatibility. With this change 1u < -1 == false.<br>
<br>
Regards,<br>
Christian<br></blockquote><div><br></div><div>See also: <a href="https://github.com/D-Programming-Language/dmd/pull/119">https://github.com/D-Programming-Language/dmd/pull/119</a> </div></div><div><br></div>-- <br>Robert<br>
<a href="http://octarineparrot.com/">http://octarineparrot.com/</a><br>