mirror of
https://github.com/dlang/phobos.git
synced 2025-04-26 13:10:35 +03:00
sumtype: fix canMatch for non-copyable ref return (#10648)
Handlers that return a non-copyable value by reference are now capable of successfully matching. Fixes #10647
This commit is contained in:
parent
3a8f31acbd
commit
40daf61851
1 changed files with 16 additions and 1 deletions
|
@ -1830,7 +1830,7 @@ class MatchException : Exception
|
|||
template canMatch(alias handler, Ts...)
|
||||
if (Ts.length > 0)
|
||||
{
|
||||
enum canMatch = is(typeof((ref Ts args) => handler(args)));
|
||||
enum canMatch = is(typeof(auto ref (ref Ts args) => handler(args)));
|
||||
}
|
||||
|
||||
///
|
||||
|
@ -1855,6 +1855,21 @@ if (Ts.length > 0)
|
|||
assert(canMatch!(OverloadSet.fun, double));
|
||||
}
|
||||
|
||||
// Allows returning non-copyable types by ref
|
||||
// https://github.com/dlang/phobos/issues/10647
|
||||
@safe unittest
|
||||
{
|
||||
static struct NoCopy
|
||||
{
|
||||
@disable this(this);
|
||||
}
|
||||
|
||||
static NoCopy lvalue;
|
||||
static ref handler(int _) => lvalue;
|
||||
|
||||
assert(canMatch!(handler, int));
|
||||
}
|
||||
|
||||
// Like aliasSeqOf!(iota(n)), but works in BetterC
|
||||
private template Iota(size_t n)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue