Skip to content

Commit a37fd5f

Browse files
authored
Merge pull request #8457 from iK4tsu/fix-sumtype-canMatch
Issue 23101 - [std.sumtype] canMatch does not account ref Signed-off-by: Luís Ferreira <[email protected]> Signed-off-by: Paul Backus <[email protected]> Merged-on-behalf-of: Atila Neves <[email protected]>
2 parents a56287d + d39c4ea commit a37fd5f

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

std/sumtype.d

+22-1
Original file line numberDiff line numberDiff line change
@@ -1830,7 +1830,7 @@ class MatchException : Exception
18301830
template canMatch(alias handler, Ts...)
18311831
if (Ts.length > 0)
18321832
{
1833-
enum canMatch = is(typeof((Ts args) => handler(args)));
1833+
enum canMatch = is(typeof((ref Ts args) => handler(args)));
18341834
}
18351835

18361836
///
@@ -2575,6 +2575,27 @@ version (D_Exceptions)
25752575
}
25762576
}
25772577

2578+
// return ref
2579+
// issue: https://issues.dlang.org/show_bug.cgi?id=23101
2580+
@safe unittest
2581+
{
2582+
static assert(!__traits(compiles, () {
2583+
SumType!(int, string) st;
2584+
return st.match!(
2585+
function int* (string x) => assert(0),
2586+
function int* (return ref int i) => &i,
2587+
);
2588+
}));
2589+
2590+
SumType!(int, string) st;
2591+
static assert(__traits(compiles, () {
2592+
return st.match!(
2593+
function int* (string x) => null,
2594+
function int* (return ref int i) => &i,
2595+
);
2596+
}));
2597+
}
2598+
25782599
private void destroyIfOwner(T)(ref T value)
25792600
{
25802601
static if (hasElaborateDestructor!T)

0 commit comments

Comments
 (0)