Skip to content

Commit d39c4ea

Browse files
committed
test(sumtype): add unittests when returning the matched value's reference
Signed-off-by: João Lourenço <[email protected]>
1 parent 6069c44 commit d39c4ea

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

std/sumtype.d

+21
Original file line numberDiff line numberDiff line change
@@ -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)