Bug 16976 – Implicit conversion from ulong to int in foreach_reverse
Status
RESOLVED
Resolution
FIXED
Severity
trivial
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-12-16T22:55:12Z
Last change time
2018-11-15T11:23:33Z
Assigned to
No Owner
Creator
Sprink
Comments
Comment #0 by sprink.noreply — 2016-12-16T22:55:12Z
On a 64-bit system where "length" is ulong, a "foreach" statement allows it to be implicitly converted to an integer if specified. But the same is not allowed in foreach_reverse.
foreach(int i, v ; [0, 1, 2])
{
// ok
}
foreach_reverse(int i, v ; [0, 1, 2])
{
// error cannot implicitly convert (__r1234.length) of type ulong to int
}
Comment #1 by sprink.noreply — 2016-12-16T22:57:23Z
Correction:
inlining the array like that seems to work as the value is known. Using anything else though it doesn't work.
int[] values = [ 0, 1, 2 ]; // dynamically
foreach_reverse(int i, v ; values)
{
// error
}