digitalmars.D.bugs - [Issue 23101] New: [std.sumtype] canMatch does not account ref
- d-bugmail puremagic.com (34/34) May 10 2022 https://issues.dlang.org/show_bug.cgi?id=23101
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 puremagic.com Reporter: jlourenco5691 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`. --
May 10 2022