Bug 11305 – Operations with array length cannot be used as a condition
Status
RESOLVED
Resolution
WORKSFORME
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-10-20T04:56:05Z
Last change time
2023-02-11T05:40:10Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
Denis Shelomovskii
Comments
Comment #0 by verylonglogin.reg — 2013-10-20T04:56:05Z
As a result of compiler rewrite we get this:
---
void main()
{
int[] arr;
if(++arr.length) { } // Error: assignment cannot be used as a condition, perhaps == was meant?
}
---
Comment #1 by b2.temp — 2019-06-30T07:59:12Z
This is because the preincrement expression is lowered.
++arr.length
is rewritten
arr.length = arr.length + 1LU
which is not allowed as IfCondition, to prevent the "=" vs "==" error.