[Issue 10915] New: std.typecons.Nullable throws in writeln() if it's null

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Aug 27 18:00:45 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10915

           Summary: std.typecons.Nullable throws in writeln() if it's null
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: minor
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: monkeyworks12 at hotmail.com


--- Comment #0 from monkeyworks12 at hotmail.com 2013-08-27 18:00:44 PDT ---
Example code that outlines my situation:

import std.array;
import std.stdio;
import std.typecons;

class NullableRange
{
    Nullable!int[] store;

    this (Nullable!int[] maybeInts)
    {
        store = maybeInts;
    }

    bool empty() { return store.empty; }

    Nullable!int front() { return store.front; }

    void popFront() { store.popFront; }
}

void main()
{
    auto arr = [Nullable!int(0), Nullable!int(1), Nullable!int()];
    auto nr  = new NullableRange(arr);
   
//core.exception.AssertError@/opt/compilers/dmd2/include/std/typecons.d(1216):
Called `get' on null Nullable!int.
    writeln(nr);
}

I think isNull() should be called before calling get() on a Nullable within
writeln(). This is proving to be very annoying if I want to print a range of
Nullable values. I suggest that something like "Nullable!int.Null" or
(Nullable!int(null)" be printed instead.

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


More information about the Digitalmars-d-bugs mailing list