Jump to page: 1 2
Thread overview
[Issue 4603] New: array(iota(1, 0)) error
Aug 09, 2010
kennytm@gmail.com
Aug 09, 2010
kennytm@gmail.com
Aug 09, 2010
kennytm@gmail.com
Aug 20, 2010
David Simcha
Aug 20, 2010
David Simcha
Apr 20, 2012
Brad Anderson
August 09, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4603

           Summary: array(iota(1, 0))  error
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: bearophile_hugs@eml.cc


--- Comment #0 from bearophile_hugs@eml.cc 2010-08-09 07:49:55 PDT ---
This generates an 'Access Violation' with dmd 2.048beta:


import std.range;
void main() {
    array(iota(1, 0));
}


The expected result of this array() is an empty dynamic array of signed
integers.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 09, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4603


kennytm@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kennytm@gmail.com
         OS/Version|Windows                     |All


--- Comment #1 from kennytm@gmail.com 2010-08-09 10:40:09 PDT ---
If you write

---

import std.range;
import std.stdio;
void main() {
    foreach (a; iota(1, 0)) {
        writeln(a);
    }
}

---

the program will never stop writing. Looks like an integer overflow bug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 09, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4603



--- Comment #2 from kennytm@gmail.com 2010-08-09 11:03:43 PDT ---
Created an attachment (id=707)
Patch for range.d to produce an empty range when pastLast <= current.

This patch produces an empty range when pastLast <= current. But this is inconsistent with the behavior of floating point iota ranges.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 09, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4603



--- Comment #3 from kennytm@gmail.com 2010-08-09 11:08:17 PDT ---
Created an attachment (id=708)
Patch for range.d to throw when pastLast <= current.

This patch simply enforces pastLast > current, so it is consistent with the floating point iota range. But it may be less useful.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 20, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4603


David Simcha <dsimcha@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dsimcha@yahoo.com


--- Comment #4 from David Simcha <dsimcha@yahoo.com> 2010-08-19 17:07:09 PDT ---
Fixed in changeset 1901.  I chose to throw in this case.  The proper way to create an empty range would be to do iota(0, 0), or iota(1, 1).  The main reason for this choice was consistency with array slicing.  For example, if bounds checking is enabled, array[3..2] throws a RangeError.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 20, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4603



--- Comment #5 from bearophile_hugs@eml.cc 2010-08-19 17:44:23 PDT ---
Throwing? No, look at Python:

>>> range(1, 0)
[]

It needs to return an empty range.

This:
foreach (i; iota(1, 0))
is the same as:
foreach (i; 1 .. 0)
Or:
for (int i = 1; i < 0; i++)

It's like an empty loop.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 20, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4603



--- Comment #6 from bearophile_hugs@eml.cc 2010-08-19 17:49:22 PDT ---
And by the way, in Python This produces an empty string slice:

>>> "abcdefg"[3:2]
''

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 20, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4603


David Simcha <dsimcha@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 20, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4603


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |


--- Comment #7 from bearophile_hugs@eml.cc 2010-08-20 05:16:23 PDT ---
Thank you for improving this bug. But I reopen the bug because I think raising an error is the wrong design. As I have explained iota() is to be meant as the ranges in for/foreach loops, so iota(1, 0) is like an empty loop, it's not an error.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 09, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4603


Andrei Alexandrescu <andrei@metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |ASSIGNED
                 CC|                            |andrei@metalanguage.com
         AssignedTo|nobody@puremagic.com        |andrei@metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2