Nullable!T with T of class type

kdevel kdevel at vogtner.de
Mon Jun 25 19:40:30 UTC 2018


Just stumbled over the following design:

    class S {...}

    class R {
       :
       Nullable!S s;
       :
    }

s was checked in code like

    R r;
    :
    if (r.s is null)
       throw new Exception ("some error message");

At runtime the following was caught:

     fatal error: caught Throwable: Called `get' on null Nullable!S

Why can't this programming error be detected at compile time? Is 
it possible
to "lower" the Nullable operations if T is a class type such that 
there
is only one level of nullification?

BTW: https://dlang.org/library/std/typecons/nullable.html 
contains duplicate sections:

     Function nullable
     Function nullable
     Struct Nullable
     Struct Nullable



More information about the Digitalmars-d-learn mailing list