Skip to content

Commit c4475e1

Browse files
committed
Fix canMatch for ref return of non-copyable type
Frontend requirement is bumped to 2.101 for access to auto ref lambdas. Phobos PR: dlang/phobos#10648
1 parent ee35912 commit c4475e1

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@ jobs:
1616
- macOS-latest
1717
dc:
1818
- dmd-latest
19-
- dmd-2.099.1
20-
- dmd-2.098.1
19+
- dmd-2.101.0
2120
- ldc-latest
22-
- ldc-1.29.0
23-
- ldc-1.28.1
24-
exclude:
25-
- os: macOS-latest
26-
- dc: dmd-2.098.1
21+
- ldc-1.31.0
2722
runs-on: ${{ matrix.os }}
2823
steps:
2924
- name: Checkout repository

dub.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"license": "BSL-1.0",
99

1010
"toolchainRequirements": {
11-
"frontend": ">=2.098"
11+
"frontend": ">=2.101"
1212
},
1313

1414
"dflags": ["-preview=fieldwise"],

src/sumtype.d

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1729,7 +1729,7 @@ class MatchException : Exception
17291729
template canMatch(alias handler, Ts...)
17301730
if (Ts.length > 0)
17311731
{
1732-
enum canMatch = is(typeof((ref Ts args) => handler(args)));
1732+
enum canMatch = is(typeof(auto ref (ref Ts args) => handler(args)));
17331733
}
17341734

17351735
///
@@ -1752,6 +1752,20 @@ template canMatch(alias handler, Ts...)
17521752
assert(canMatch!(OverloadSet.fun, double));
17531753
}
17541754

1755+
// Allows returning non-copyable types by ref
1756+
// https://github.com/dlang/phobos/issues/10647
1757+
@safe unittest {
1758+
static struct NoCopy
1759+
{
1760+
@disable this(this);
1761+
}
1762+
1763+
static NoCopy lvalue;
1764+
static ref handler(int _) => lvalue;
1765+
1766+
assert(canMatch!(handler, int));
1767+
}
1768+
17551769
// Like aliasSeqOf!(iota(n)), but works in BetterC
17561770
private template Iota(size_t n)
17571771
{

0 commit comments

Comments
 (0)