[Issue 5020] Forward implicit bool conversions to alias this
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Oct 8 13:15:10 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5020
Shin Fujishiro <rsinfu at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
--- Comment #1 from Shin Fujishiro <rsinfu at 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: -------
More information about the Digitalmars-d-bugs
mailing list