[Issue 10638] New: Assignment can't be used as a condition
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jul 14 04:44:08 PDT 2013
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: nobody at puremagic.com
ReportedBy: freeslave93 at gmail.com
--- Comment #0 from Roman <freeslave93 at 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: -------
More information about the Digitalmars-d-bugs
mailing list