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


Shin Fujishiro <rsi...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


--- Comment #1 from Shin Fujishiro <rsi...@gmail.com> 2010-10-08 13:14:45 PDT 
---
It's simply Expression::checkToBoolean() not looking for alias this.  Here's a
proposed patch against dmd r707:
====================
--- src/expression.c
+++ src/expression.c
@@ -1269,6 +1269,15 @@ Expression *Expression::checkToBoolean(Scope *sc)
             e = e->semantic(sc);
             return e;
         }
+
+        // Forward to aliasthis.
+        if (ad->aliasthis)
+        {
+            Expression *e = new DotIdExp(loc, this, ad->aliasthis->ident);
+            e = e->semantic(sc);
+            e = e->checkToBoolean(sc);
+            return e;
+        }
     }

     if (!type->checkBoolean())
====================

Note: Since CastExp takes care of aliasthis, adding a test for ad->aliasthis in
a preceding if-block also makes the repro code work.  But the if-block doesn't
check for implicit convertible-ness (i.e. checkToBoolean), and it will
eventually allow the following wrong code to be accepted:

void main()
{
    S s;
    if (s) {}   // wrong
}
struct S
{
    struct R {} // not implicitly convertible to bool
    R r;
    alias r this;
}

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

Reply via email to