www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9559] New: Range of Nullable doesn't work with std.array.array

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9559

           Summary: Range of Nullable doesn't work with std.array.array
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: justin economicmodeling.com


--- Comment #0 from Justin Whear <justin economicmodeling.com> 2013-02-21
11:24:22 PST ---
Using std.array.array on a range of Nullable!T causes a runtime error if at
least one of the elements is set to null.  Test case:
----------------------
import std.algorithm;
import std.typecons;
void main()
{
       alias Nullable!int I;
    auto ints = [0, 1, 2].map!(i => i & 1 ? I.init : I(i));
    auto asArray = std.array.array(ints);
}
----------------------

Produces the following error:
object.Exception /usr/include/dmd/phobos/std/typecons.d(1181): Enforcement
failed

Full backtrace here: http://pastebin.com/wMFRKk6L

The enforcement exception occurs in Nullable's get() function (I'm using 2.062,
I noticed that this has been changed to an assert in HEAD) and Nullable has an
alias this to get. Best guess is that this is actually a problem in emplace or
array's usage of it.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 21 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9559



--- Comment #1 from Justin Whear <justin economicmodeling.com> 2013-02-21
12:00:31 PST ---
I don't have a good testing environment at the moment, but it looks like the
bug might be here:
https://github.com/D-Programming-Language/phobos/blob/master/std/conv.d#L3581

If I understand this correctly, this static if will succeed because the
Nullable!int constructor will accept another Nullable!int due to the alias
this.  When the constructor is called, the alias this causes the get() function
to be called in order to resolve the Nullable being copied to an int.

Possible fix: add a constructor to Nullable that takes typeof(this) and
correctly checks isNull.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 21 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9559


monarchdodra gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra gmail.com


--- Comment #2 from monarchdodra gmail.com 2013-02-21 13:26:31 PST ---
(In reply to comment #1)
 I don't have a good testing environment at the moment, but it looks like the
 bug might be here:
 https://github.com/D-Programming-Language/phobos/blob/master/std/conv.d#L3581
 
 If I understand this correctly, this static if will succeed because the
 Nullable!int constructor will accept another Nullable!int due to the alias
 this.  When the constructor is called, the alias this causes the get() function
 to be called in order to resolve the Nullable being copied to an int.
 
 Possible fix: add a constructor to Nullable that takes typeof(this) and
 correctly checks isNull.

This gets fixed by my existing fix for emplace. The pull is here: https://github.com/D-Programming-Language/phobos/pull/1082 And I just added a unittest for this specific bug: https://github.com/monarchdodra/phobos/commit/10025b835e564d17fd960d461e965e9bb80d115d -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 21 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9559



--- Comment #3 from Justin Whear <justin economicmodeling.com> 2013-02-21
13:45:45 PST ---
(In reply to comment #2)
 (In reply to comment #1)
 I don't have a good testing environment at the moment, but it looks like the
 bug might be here:
 https://github.com/D-Programming-Language/phobos/blob/master/std/conv.d#L3581
 
 If I understand this correctly, this static if will succeed because the
 Nullable!int constructor will accept another Nullable!int due to the alias
 this.  When the constructor is called, the alias this causes the get() function
 to be called in order to resolve the Nullable being copied to an int.
 
 Possible fix: add a constructor to Nullable that takes typeof(this) and
 correctly checks isNull.

This gets fixed by my existing fix for emplace. The pull is here: https://github.com/D-Programming-Language/phobos/pull/1082 And I just added a unittest for this specific bug: https://github.com/monarchdodra/phobos/commit/10025b835e564d17fd960d461e965e9bb80d115d

Excellent. I'd love to see this in the next release. Unfortunately, it looks like the use of UFCS in my test case is causing the auto-tester to choke. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 21 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9559



--- Comment #4 from github-bugzilla puremagic.com 2013-08-28 01:35:19 PDT ---
Commit pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/e951b2cf465614e87379c4f0b501ee0f1d57a9ad
Issue 9559 - Range of Nullable doesn't work with std.array.array

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 28 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9559


David Nadlinger <code klickverbot.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |code klickverbot.at
         Resolution|                            |FIXED


--- Comment #5 from David Nadlinger <code klickverbot.at> 2013-08-28 01:40:53
PDT ---
Fixed in Git master.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 28 2013