File tree 1 file changed +34
-8
lines changed
1 file changed +34
-8
lines changed Original file line number Diff line number Diff line change @@ -2792,13 +2792,24 @@ struct Nullable(T)
2792
2792
}
2793
2793
}
2794
2794
2795
- this ( ref return scope inout Nullable ! T rhs) inout
2795
+ static if (__traits(hasPostblit, T))
2796
2796
{
2797
- _isNull = rhs._isNull;
2798
- if (! _isNull)
2799
- _value.payload = rhs._value.payload;
2800
- else
2801
- _value = DontCallDestructorT.init;
2797
+ this (this )
2798
+ {
2799
+ if (! _isNull)
2800
+ _value.payload.__xpostblit();
2801
+ }
2802
+ }
2803
+ else static if (__traits(hasCopyConstructor, T))
2804
+ {
2805
+ this (ref return scope inout Nullable! T rhs) inout
2806
+ {
2807
+ _isNull = rhs._isNull;
2808
+ if (! _isNull)
2809
+ _value.payload = rhs._value.payload;
2810
+ else
2811
+ _value = DontCallDestructorT.init;
2812
+ }
2802
2813
}
2803
2814
2804
2815
/**
@@ -9546,13 +9557,28 @@ unittest
9546
9557
{
9547
9558
int b;
9548
9559
@disable this (this );
9549
- this (ref return scope inout S rhs) inout
9560
+ this (ref return scope inout S rhs) inout
9550
9561
{
9551
9562
this .b = rhs.b + 1 ;
9552
9563
}
9553
9564
}
9554
9565
9555
9566
Nullable! S s1 = S(1 );
9567
+ assert (s1.get ().b == 2 );
9568
+ Nullable! S s2 = s1;
9569
+ assert (s2.get ().b == 3 );
9570
+ }
9571
+
9572
+ @safe unittest
9573
+ {
9574
+ static struct S
9575
+ {
9576
+ int b;
9577
+ this (this ) { ++ b; }
9578
+ }
9579
+
9580
+ Nullable! S s1 = S(1 );
9581
+ assert (s1.get ().b == 2 );
9556
9582
Nullable! S s2 = s1;
9557
- assert (s2.get ().b > s1. get ().b );
9583
+ assert (s2.get ().b == 3 );
9558
9584
}
You can’t perform that action at this time.
0 commit comments