[Issue 23101] New: [std.sumtype] canMatch does not account ref
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue May 10 19:21:38 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23101
Issue ID: 23101
Summary: [std.sumtype] canMatch does not account ref
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: enhancement
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: jlourenco5691 at gmail.com
SumType allows this bit of code:
```
SumType!(int, string) st;
st.match!(
function ref int(string _) => assert(0),
function ref int(ref int i) => i,
);
```
However, it does not allow returning a pointer to i:
```
SumType!(int, string) st;
st.match!(
function ref int*(string _) => assert(0),
function ref int*(ref int i) => &i,
);
```
This is because `canMatch` does not account for `ref`. The template
`valueTypes` stores all types of the member values and uses SumTypes's `get`
function, which returns a `ref`. However, ref does not persist and the type is
not sent to `canMatch` as a `ref`.
--
More information about the Digitalmars-d-bugs
mailing list