http://d.puremagic.com/issues/show_bug.cgi?id=10638
Summary: Assignment can't be used as a condition Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nob...@puremagic.com ReportedBy: freeslav...@gmail.com --- Comment #0 from Roman <freeslav...@gmail.com> 2013-07-14 04:44:07 PDT --- Suppose code void main() { int i = 0; if (i = 1) { //...... } } dmd compiler generates error: "assignment cannot be used as a condition, perhaps == was meant?" But next code passed successfully: void main() { if (int i = 1) { //...... } } It's a bit odd that assignment can not be used as condition while declaration can be. It works fine if we replace first code snippet with this: void main() { int i = 0; if (cast(bool)(i = 1)) { //...... } } I guess assignment has no implicit cast to bool, it's weird too. If it's not error, please, explain me the reasons of this restriction. Also dlang.org defines ifStatement as "if ( IfCondition ) ThenStatement", where ifCondition can be Expression (hence AssignExpression too), but it seems it does not work at practice. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------