Skip to content

Commit 81b37fd

Browse files
committed
[Refactoring] Support refactoring for case let patterns
Previously we only supported `case` patterns that bound with a `let` inside the associated value like `case .success(let value)`. With this change, we also support `case let .success(value)`. Fixes rdar://79279846 [SR-14772]
1 parent 38a8b00 commit 81b37fd

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)