[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]
This commit is contained in:
Alex Hoppen
2021-06-14 12:29:08 +02:00
parent 38a8b008bc
commit 81b37fdb4c
2 changed files with 12 additions and 1 deletions

View File

@@ -4571,7 +4571,8 @@ struct CallbackCondition {
/// }
/// ```
CallbackCondition(const Decl *Subject, const CaseLabelItem *CaseItem) {
if (auto *EEP = dyn_cast<EnumElementPattern>(CaseItem->getPattern())) {
if (auto *EEP = dyn_cast<EnumElementPattern>(
CaseItem->getPattern()->getSemanticsProvidingPattern())) {
// `case .<func>(let <bind>)`
initFromEnumPattern(Subject, EEP);
}

View File

@@ -265,6 +265,16 @@ func testPatterns() async throws {
// STRING-TUPLE-RESULT-NEXT: print("oh no")
// STRING-TUPLE-RESULT-NEXT: }
// 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
stringTupleResult { res in
switch res {
case let .success((x, y)):
print(x, y)
case .failure:
print("oh no")
}
}
// 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
mixedTupleResult { res in
if case .failure(let err) = res {