[Issue 22572] New: Cannot define SumType over immutable struct with Nullable
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Dec 6 12:24:06 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=22572
Issue ID: 22572
Summary: Cannot define SumType over immutable struct with
Nullable
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: default_357-line at yahoo.de
Not sure if Phobos or DMD issue.
Consider this code:
import std;
immutable struct Value
{
Nullable!string n;
}
void main() {
SumType!Value value;
}
This gets /dlang/dmd-nightly/linux/bin64/../../src/phobos/std/sumtype.d(1985):
Error: static assert: "`handlers[0]` of type `template` never matches"
If we replace Nullable with a simpler struct:
struct CopyConstruct
{
this(ref CopyConstruct other) { }
}
immutable struct Value
{
CopyConstruct c;
}
void main() {
SumType!Value value;
}
Then we get the revealing error:
Error: Generating an `inout` copy constructor for `struct onlineapp.Value`
failed, therefore instances of it are uncopyable
It looks like Nullable's copy constructor does not play well with immutable
structs.
The strange `handler never matches` error above seems to only arise because DMD
manages to defer this error until the SumType handler. But this is not the
primary issue.
--
More information about the Digitalmars-d-bugs
mailing list