summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2019-01-29 08:24:58 +0100
committerEugen Wissner <belka@caraus.de>2019-01-29 08:24:58 +0100
commit410b865df9b0dcc7496fa7e0e355f07b07b20354 (patch)
treec230ce4a1c4d1f6b7d9e79c74c3a97b338125351
parent4566cf7857ee25b5c3c52f93a46e8d0e903d3f0a (diff)
downloadtanya-410b865df9b0dcc7496fa7e0e355f07b07b20354.tar.gz
typecons.Option: Fix assigning nothing
-rw-r--r--source/tanya/typecons.d20
1 files changed, 18 insertions, 2 deletions
diff --git a/source/tanya/typecons.d b/source/tanya/typecons.d
index b65863a..d60dc26 100644
--- a/source/tanya/typecons.d
+++ b/source/tanya/typecons.d
@@ -367,8 +367,15 @@ struct Option(T)
ref typeof(this) opAssign(U)(ref U that)
if (is(U == Option))
{
- this.value = that;
- this.isNothing_ = that.isNothing;
+ if (that.isNothing)
+ {
+ reset();
+ }
+ else
+ {
+ this.value = that.get;
+ this.isNothing_ = false;
+ }
return this;
}
@@ -515,6 +522,15 @@ struct Option(T)
assert(OptionT(Hashable(1U)).toHash() == 1U);
}
+// Can assign Option that is nothing
+@nogc nothrow pure @safe unittest
+{
+ auto option1 = Option!int(5);
+ Option!int option2;
+ option1 = option2;
+ assert(option1.isNothing);
+}
+
/**
* Creates a new $(D_PSYMBOL Option).
*