Bug 5891 – hasLength!iota is false

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-04-26T06:19:00Z
Last change time
2011-05-06T02:21:58Z
Assigned to
nobody
Creator
dsimcha

Comments

Comment #0 by dsimcha — 2011-04-26T06:19:17Z
With the latest SVN versions of Phobos and DMD the following static assert fails: import std.range; void main() { auto myIota = iota(1000); static assert(hasLength!(typeof(myIota))); } IMHO this is a blocker for releasing 2.053 because iota is very frequently used with parallel foreach loops and parallel foreach is much less efficient if iterating over a range without a length.
Comment #1 by kennytm — 2011-04-26T08:11:27Z
(SVN? You mean git?) The problem is length() is an auto-return function, and somehow typeof() cannot find the return type from this function: -------------------------------------------------- import std.range; struct X { @property auto length() { return 0; } } pragma(msg, typeof(X.init.length)); // () -------------------------------------------------- Because of this, is(typeof(X.init.length) : ulong) cannot be true, and return hasLength returns false. This is more a DMD problem than a Phobos problem.
Comment #2 by dsimcha — 2011-05-05T15:45:50Z
Of course the DMD bug should be fixed but Iota is too important to fail, so this specific case has been worked around: https://github.com/D-Programming-Language/phobos/commit/9c7fe081f8ec5cec6822f3801b3dee6a85d22e45
Comment #3 by kennytm — 2011-05-06T02:21:58Z
(In reply to comment #2) > Of course the DMD bug should be fixed but Iota is too important to fail, so > this specific case has been worked around: > > https://github.com/D-Programming-Language/phobos/commit/9c7fe081f8ec5cec6822f3801b3dee6a85d22e45 OK. The DMD bug is now filed as issue 5933.