Skip to content

Commit 23eee39

Browse files
authored
Merge pull request #93 from pbackus/fix-phobos-10647
Fix canMatch for ref return of non-copyable type
2 parents 0aa762d + bd73256 commit 23eee39

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,13 @@ jobs:
1616
- macOS-latest
1717
dc:
1818
- dmd-latest
19-
- dmd-2.099.1
20-
- dmd-2.098.1
19+
- dmd-2.101.2
2120
- ldc-latest
22-
- ldc-1.29.0
23-
- ldc-1.28.1
21+
- ldc-1.31.0
2422
exclude:
2523
# macOS requires DMD >= 2.107.1
2624
- os: macOS-latest
27-
dc: dmd-2.099.1
28-
- os: macOS-latest
29-
dc: dmd-2.098.1
25+
dc: dmd-2.101.2
3026
runs-on: ${{ matrix.os }}
3127
steps:
3228
- 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)