Skip to content

Commit 6069c44

Browse files
committed
fix(sumtype): template canMatch does not account for ref when matching
The template `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`. Because of this, when matching, `canMatch` will fail as it will test for a copy, and returning a reference of that value results in escaping it. Fix Issue 23101 Signed-off-by: João Lourenço <jlourenco5691@gmail.com>
1 parent a56287d commit 6069c44

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

std/sumtype.d

Lines changed: 1 addition & 1 deletion
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
///

0 commit comments

Comments
 (0)