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 }
Comment #2 by bitter.taste — 2016-12-21T08:06:37Z
Comment #3 by github-bugzilla — 2018-11-15T11:23:32Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/1003fe69843de58238f2b7823ddd1f22eeb7bc0b Fix issue 16976 - Do not convert blindly the size of an iterable https://github.com/dlang/dmd/commit/0c1fdaf085e59b691b9591490ac9a5504524c48d Merge pull request #8941 from dlang/thewilsonator-patch-3 Fix issue 16976 - Do not convert blindly the size of an iterable merged-on-behalf-of: Nicholas Wilson <[email protected]>