Skip to content

Commit 6d34fd9

Browse files
committed
Handle parent vars in async transform
If we're in a case stmt body, any DeclRefExprs to vars bound by a pattern will actually be to an implicit var decl that's declared for the body. We therefore need to walk to its "parent" to get to the var referenced by the pattern, which will have the correct entries in the naming and placeholder maps.
1 parent f28284d commit 6d34fd9

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/IDE/Refactoring.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6140,6 +6140,14 @@ class AsyncConverter : private SourceEntityWalker {
61406140
// TODO: Handle Result.get as well
61416141
if (auto *DRE = dyn_cast<DeclRefExpr>(E)) {
61426142
if (auto *D = DRE->getDecl()) {
6143+
// Look through to the parent var decl if we have one. This ensures we
6144+
// look at the var in a case stmt's pattern rather than the var that's
6145+
// implicitly declared in the body.
6146+
if (auto *VD = dyn_cast<VarDecl>(D)) {
6147+
if (auto *Parent = VD->getParentVarDecl())
6148+
D = Parent;
6149+
}
6150+
61436151
bool AddPlaceholder = Placeholders.count(D);
61446152
StringRef Name = newNameFor(D, false);
61456153
if (AddPlaceholder || !Name.empty())

test/refactoring/ConvertAsync/convert_pattern.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ func testPatterns() async throws {
293293
// MIXED-TUPLE-RESULT-NEXT: let ((x, y), z) = res
294294
// MIXED-TUPLE-RESULT-NEXT: let ((x1, _), z1) = res
295295
// MIXED-TUPLE-RESULT-NEXT: print("a", x, y, z)
296-
// MIXED-TUPLE-RESULT-NEXT: print("b", x, z)
296+
// MIXED-TUPLE-RESULT-NEXT: print("b", x1, z1)
297297
// MIXED-TUPLE-RESULT-NEXT: } catch let err {
298298
// MIXED-TUPLE-RESULT-NEXT: print("oh no")
299299
// MIXED-TUPLE-RESULT-NEXT: print("oh no again")

0 commit comments

Comments
 (0)