Thread overview | |||||
---|---|---|---|---|---|
|
October 08, 2010 [Issue 5020] New: Forward implicit bool conversions to alias this | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=5020 Summary: Forward implicit bool conversions to alias this Product: D Version: D2 Platform: All OS/Version: All Status: NEW Keywords: rejects-valid Severity: normal Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: rsinfu@gmail.com --- Comment #0 from Shin Fujishiro <rsinfu@gmail.com> 2010-10-08 12:14:52 PDT --- Alias this isn't implemented for implicit conversions to bool in conditional expressions. The following presumably valid code doesn't compile: -------------------- void main() { S s; if (!s) {} // (4) } struct S { bool cond; alias cond this; } -------------------- % dmd -o- -c test.d test.d(4): Error: expression s of type S does not have a boolean value -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 08, 2010 [Issue 5020] Forward implicit bool conversions to alias this | ||||
---|---|---|---|---|
| ||||
Posted in reply to Shin Fujishiro | http://d.puremagic.com/issues/show_bug.cgi?id=5020 Shin Fujishiro <rsinfu@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |patch --- Comment #1 from Shin Fujishiro <rsinfu@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: ------- |
December 21, 2010 [Issue 5020] Forward implicit bool conversions to alias this | ||||
---|---|---|---|---|
| ||||
Posted in reply to Shin Fujishiro | http://d.puremagic.com/issues/show_bug.cgi?id=5020 bearophile_hugs@eml.cc changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |bearophile_hugs@eml.cc Resolution| |FIXED --- Comment #2 from bearophile_hugs@eml.cc 2010-12-21 01:50:31 PST --- Fixed in DMD 2.051 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation