Skip to content

Commit 78ec3ba

Browse files
authored
Merge pull request #17677 from nkcsgexi/composite-cherry-pick
[4.2] migrator: handle the composite change of updating raw-representable to type alias and rename the referenced variables simultaneously. rdar://41732485
2 parents 89b4664 + d710516 commit 78ec3ba

File tree

5 files changed

+16
-3
lines changed

5 files changed

+16
-3
lines changed

lib/Migrator/APIDiffMigratorPass.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,8 +1052,10 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
10521052
bool walkToExprPre(Expr *E) override {
10531053
if (E->getSourceRange().isInvalid())
10541054
return false;
1055-
if (handleRevertRawRepresentable(E))
1056-
return false;
1055+
if (handleRevertRawRepresentable(E)) {
1056+
// The name may also change, so we should keep visiting.
1057+
return true;
1058+
}
10571059
if (handleQualifiedReplacement(E))
10581060
return false;
10591061
if (handleAssignDestMigration(E))

test/Migrator/Inputs/Cities.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ public struct AwesomeCityAttribute: RawRepresentable {
8484

8585
public class Wrapper {
8686
public struct Attribute: RawRepresentable {
87-
public init?(rawValue: String) { self.rawValue = rawValue }
87+
public static let KnownAttr = Wrapper.Attribute(rawValue: "")
88+
public init(rawValue: String) { self.rawValue = rawValue }
8889
public var rawValue: String
8990
public typealias RawValue = String
9091
}

test/Migrator/Inputs/string-representable.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,4 +260,12 @@
260260
"RightComment": "String",
261261
"ModuleName": "Cities"
262262
},
263+
{
264+
"DiffItemKind": "TypeMemberDiffItem",
265+
"Usr": "s:6Cities7WrapperC9AttributeV9KnownAttrAEvpZ",
266+
"OldPrintedName": "KnownAttr",
267+
"OldTypeName": "Wrapper.Attribute",
268+
"NewPrintedName": "NewKnownAttr",
269+
"NewTypeName": "NewAttributeWrapper"
270+
},
263271
]

test/Migrator/string-representable.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func revert(_ a: AwesomeCityAttribute, b: Wrapper.Attribute) {
5353
_ = Wrapper.Attribute(rawValue: "somevalue")
5454
_ = Wrapper.Attribute.init(rawValue: "somevalue")
5555
_ = b.rawValue
56+
_ = Wrapper.Attribute.KnownAttr.rawValue
5657
}
5758

5859

test/Migrator/string-representable.swift.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func revert(_ a: AwesomeCityAttribute, b: Wrapper.Attribute) {
5353
_ = "somevalue"
5454
_ = "somevalue"
5555
_ = b
56+
_ = NewAttributeWrapper.NewKnownAttr
5657
}
5758

5859

0 commit comments

Comments
 (0)