Skip to content

Commit

Permalink
Merge pull request #1340 from 9rnsr/fix10268
Browse files Browse the repository at this point in the history
[REG2.063] Issue 10268 - std.typecons.Nullable!JSONValue - error instantiating
  • Loading branch information
andralex committed Jun 9, 2013
2 parents 783902c + 2c1b1ff commit e9d5202
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion std/typecons.d
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,8 @@ struct Nullable(T)
/**
Constructor initializing $(D this) with $(D value).
*/
this()(T value) inout
//this()(inout T value) inout // proper signature
this(U:T)(inout U value) inout // workaround for BUG 10313
{
_value = value;
_isNull = false;
Expand Down Expand Up @@ -1421,6 +1422,48 @@ unittest
c = a;
}
}
unittest
{
// Bugzilla 10268
import std.json;
JSONValue value = void;
value.type = JSON_TYPE.NULL;
auto na = Nullable!JSONValue(value);

struct S1 { int val; }
struct S2 { int* val; }
struct S3 { immutable int* val; }

{
auto sm = S1(1);
immutable si = immutable S1(1);
static assert( __traits(compiles, { auto x1 = Nullable!S1(sm); }));
static assert( __traits(compiles, { auto x2 = immutable Nullable!S1(sm); }));
static assert( __traits(compiles, { auto x3 = Nullable!S1(si); }));
static assert( __traits(compiles, { auto x4 = immutable Nullable!S1(si); }));
}

auto nm = 10;
immutable ni = 10;

{
auto sm = S2(&nm);
immutable si = immutable S2(&ni);
static assert( __traits(compiles, { auto x = Nullable!S2(sm); }));
static assert(!__traits(compiles, { auto x = immutable Nullable!S2(sm); }));
static assert(!__traits(compiles, { auto x = Nullable!S2(si); }));
static assert( __traits(compiles, { auto x = immutable Nullable!S2(si); }));
}

{
auto sm = S3(&ni);
immutable si = immutable S3(&ni);
static assert( __traits(compiles, { auto x = Nullable!S3(sm); }));
static assert( __traits(compiles, { auto x = immutable Nullable!S3(sm); }));
static assert( __traits(compiles, { auto x = Nullable!S3(si); }));
static assert( __traits(compiles, { auto x = immutable Nullable!S3(si); }));
}
}

/**
Just like $(D Nullable!T), except that the null state is defined as a
Expand Down

0 comments on commit e9d5202

Please sign in to comment.