Skip to content

Commit 08b4eab

Browse files
authored
Merge pull request #37899 from ahoppen/pr/case-let-refactoring
[Refactoring] Support refactoring for `case let` patterns
2 parents 1b8cc91 + 81b37fd commit 08b4eab

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/IDE/Refactoring.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4571,7 +4571,8 @@ struct CallbackCondition {
45714571
/// }
45724572
/// ```
45734573
CallbackCondition(const Decl *Subject, const CaseLabelItem *CaseItem) {
4574-
if (auto *EEP = dyn_cast<EnumElementPattern>(CaseItem->getPattern())) {
4574+
if (auto *EEP = dyn_cast<EnumElementPattern>(
4575+
CaseItem->getPattern()->getSemanticsProvidingPattern())) {
45754576
// `case .<func>(let <bind>)`
45764577
initFromEnumPattern(Subject, EEP);
45774578
}

test/refactoring/ConvertAsync/convert_pattern.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,16 @@ func testPatterns() async throws {
265265
// STRING-TUPLE-RESULT-NEXT: print("oh no")
266266
// STRING-TUPLE-RESULT-NEXT: }
267267

268+
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=STRING-TUPLE-RESULT %s
269+
stringTupleResult { res in
270+
switch res {
271+
case let .success((x, y)):
272+
print(x, y)
273+
case .failure:
274+
print("oh no")
275+
}
276+
}
277+
268278
// RUN: %refactor-check-compiles -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=MIXED-TUPLE-RESULT %s
269279
mixedTupleResult { res in
270280
if case .failure(let err) = res {

0 commit comments

Comments
 (0)