[Issue 22176] New: Nullable creates autogenerated opAssign, triggering invariants
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Aug 4 07:53:21 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=22176
Issue ID: 22176
Summary: Nullable creates autogenerated opAssign, triggering
invariants
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: regression
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: default_357-line at yahoo.de
Consider the following code:
import std.typecons;
struct S
{
int i;
invariant(i != 0);
Nullable!int k;
}
void main() {
S s;
s = S(5);
}
Previously, that invariant was not a problem because "s = S(5)" is a plain
copy, because no type in or under S requires generated opAssign.
With DMD 2.095.1, Nullable gained an `opAssign()(Nullable!T)` overload. This
means that now, any type that contains a Nullable gets an autogenerated
`opAssign` method, which triggers the invariant check.
"Non-init" is a very common invariant in domain-data, and T.init is a very
common value in ranges, which frequently reassign fields. So this is rather
painful.
Since that opAssign was only added to handle the `get` deprecation and `get` is
now removed, maybe it can be reverted?
--
More information about the Digitalmars-d-bugs
mailing list