Skip to content

Commit

Permalink
Fix Issue 19226 - std.typecons.Nullable(T, T nullValue) doesn't fully…
Browse files Browse the repository at this point in the history
… handle non-self-equal nullValue
  • Loading branch information
n8sh committed Sep 8, 2018
1 parent 217c9af commit 75a9b04
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion std/typecons.d
Original file line number Diff line number Diff line change
Expand Up @@ -3445,7 +3445,7 @@ Returns:
}
//Need to use 'is' if T is a float type
//because NaN != NaN
else static if (isFloatingPoint!T)
else static if (__traits(compiles, { static assert(!(nullValue == nullValue)); }))
{
return _value is nullValue;
}
Expand All @@ -3466,6 +3466,14 @@ Returns:
assert(!ni.isNull);
}

@system unittest
{
assert(typeof(this).init.isNull, typeof(this).stringof ~
".isNull does not work correctly because " ~ typeof(T).stringof ~
" has an == operator that is non-reflexive and could not be " ~
" determined before runtime to be non-reflexive!");
}

// https://issues.dlang.org/show_bug.cgi?id=11135
// disable test until https://issues.dlang.org/show_bug.cgi?id=15316 gets fixed
version (none) @system unittest
Expand Down Expand Up @@ -3640,6 +3648,17 @@ if (is (typeof(nullValue) == T))
assert(a.isNull);
}

@safe unittest
{
// issue 19226 - fully handle non-self-equal nullValue
static struct S
{
float f;
}
alias N = Nullable!(S, S.init);
assert(N(S.init).isNull);
}

@safe unittest
{
static int f(scope const Nullable!(int, int.min) x) {
Expand Down

0 comments on commit 75a9b04

Please sign in to comment.