Skip to content

Commit de925d1

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 1666c2b commit de925d1

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
@@ -4580,7 +4580,8 @@ struct CallbackCondition {
45804580
/// }
45814581
/// ```
45824582
CallbackCondition(const Decl *Subject, const CaseLabelItem *CaseItem) {
4583-
if (auto *EEP = dyn_cast<EnumElementPattern>(CaseItem->getPattern())) {
4583+
if (auto *EEP = dyn_cast<EnumElementPattern>(
4584+
CaseItem->getPattern()->getSemanticsProvidingPattern())) {
45844585
// `case .<func>(let <bind>)`
45854586
initFromEnumPattern(Subject, EEP);
45864587
}

test/refactoring/ConvertAsync/convert_pattern.swift

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

275+
// 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
276+
stringTupleResult { res in
277+
switch res {
278+
case let .success((x, y)):
279+
print(x, y)
280+
case .failure:
281+
print("oh no")
282+
}
283+
}
284+
275285
// 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
276286
mixedTupleResult { res in
277287
if case .failure(let err) = res {

0 commit comments

Comments
 (0)