[Issue 22572] Cannot define SumType over immutable struct with Nullable
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Feb 9 14:46:36 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=22572
Paul Backus <snarwin+bugzilla at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |snarwin+bugzilla at gmail.com
--- Comment #1 from Paul Backus <snarwin+bugzilla at gmail.com> ---
There's definitely a SumType issue here:
---
import std.sumtype;
struct CopyConstruct
{
this(ref inout CopyConstruct other) inout { }
}
immutable struct Value
{
CopyConstruct c;
}
alias _ = SumType!Value;
---
The example above produces the following error message, as of DMD/Phobos
2.098.1:
---
/dlang/dmd/linux/bin64/../../src/phobos/std/sumtype.d(1998): Error: static
assert: "`handlers[0]` of type `template` never matches"
/dlang/dmd/linux/bin64/../../src/phobos/std/sumtype.d(1590):
instantiated from here: `matchImpl!(inout(SumType!(immutable(Value))))`
/dlang/dmd/linux/bin64/../../src/phobos/std/sumtype.d(452): instantiated
from here: `match!(inout(SumType!(immutable(Value))))`
onlineapp.d(13): instantiated from here: `SumType!(immutable(Value))`
---
The source of the error is this line:
https://github.com/dlang/phobos/blob/v2.098.1/std/sumtype.d#L452
Compiling with -verrors=spec reveals the following gagged error, which is
ultimately responsible for the failure:
---
(spec:1) src/sumtype.d(389): Error: `inout` on `return` means `inout` must be
on a parameter as well for `pure nothrow @nogc @safe inout(Storage)(ref
immutable(Value) value)`
---
SumType's copy constructor incorrectly assumes that, when copying from an
`inout(SumType) other`, the value stored in `other` will also be
inout-qualified. However, this is not the case when one of other's members is
an immutable struct, because the qualifier combination `immutable inout`
collapses to just `immutable`.
--
More information about the Digitalmars-d-bugs
mailing list