Skip to content

Commit 3e8b076

Browse files
committed
PR Review
1 parent 51176d4 commit 3e8b076

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

lib/Parse/Parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ ParsedDeclName swift::parseDeclName(StringRef name) {
14061406
}
14071407

14081408
// If the base name is prefixed by "subscript", it's an subscript.
1409-
if (baseName.startswith("subscript")) {
1409+
if (baseName == "subscript") {
14101410
result.IsSubscript = true;
14111411
}
14121412

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,7 +2000,7 @@ static void fixItAvailableAttrRename(InFlightDiagnostic &diag,
20002000
// Continue on to diagnose any argument label renames.
20012001

20022002
} else if (parsed.BaseName == "init" && isa_and_nonnull<CallExpr>(call)) {
2003-
auto *CE = dyn_cast<CallExpr>(call);
2003+
auto *CE = cast<CallExpr>(call);
20042004

20052005
// For initializers, replace with a "call" of the context type...but only
20062006
// if we know we're doing a call (rather than a first-class reference).
@@ -2022,6 +2022,14 @@ static void fixItAvailableAttrRename(InFlightDiagnostic &diag,
20222022
if (auto *CE = dyn_cast_or_null<CallExpr>(call)) {
20232023
// Renaming from CallExpr to SubscriptExpr. Remove function name and
20242024
// replace parens with square brackets.
2025+
2026+
if (auto *DSCE = dyn_cast<DotSyntaxCallExpr>(CE->getFn())) {
2027+
if (DSCE->getBase()->isImplicit()) {
2028+
// If self is implicit, self must be inserted before subscript syntax.
2029+
diag.fixItInsert(CE->getStartLoc(), "self");
2030+
}
2031+
}
2032+
20252033
diag.fixItReplace(CE->getFn()->getEndLoc(), "[");
20262034
diag.fixItReplace(CE->getEndLoc(), "]");
20272035
}
@@ -2036,12 +2044,12 @@ static void fixItAvailableAttrRename(InFlightDiagnostic &diag,
20362044
baseReplace += parsed.BaseName;
20372045

20382046
if (parsed.IsFunctionName && isa_and_nonnull<SubscriptExpr>(call)) {
2039-
auto *SE = dyn_cast<SubscriptExpr>(call);
2047+
auto *SE = cast<SubscriptExpr>(call);
2048+
20402049
// Renaming from SubscriptExpr to CallExpr. Insert function name and
20412050
// replace square brackets with parens.
2042-
20432051
diag.fixItReplace(SE->getIndex()->getStartLoc(),
2044-
("." + baseReplace.str()).str());
2052+
("." + baseReplace.str() + "(").str());
20452053
diag.fixItReplace(SE->getEndLoc(), ")");
20462054
} else {
20472055
if (parsed.IsFunctionName && parsed.ArgumentLabels.empty() &&
@@ -3043,7 +3051,7 @@ bool ExprAvailabilityWalker::diagnoseDeclRefAvailability(
30433051
if (diagnoseIncDecRemoval(D, R, attr))
30443052
return true;
30453053
if (isa_and_nonnull<ApplyExpr>(call) &&
3046-
diagnoseMemoryLayoutMigration(D, R, attr, dyn_cast<ApplyExpr>(call)))
3054+
diagnoseMemoryLayoutMigration(D, R, attr, cast<ApplyExpr>(call)))
30473055
return true;
30483056
}
30493057

test/attr/attr_availability.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,15 +1203,20 @@ struct UnavailableSubscripts {
12031203

12041204
subscript(arg1 arg1: Int, arg2 arg2: Int, arg3 arg3: Int) -> Int { 3 }
12051205

1206+
@available(*, deprecated, renamed: "subscriptTo(_:)")
1207+
subscript(to to: Int) -> Int { 3 }
1208+
func subscriptTo(_ index: Int) -> Int { 3 }
1209+
12061210
func testUnavailableSubscripts(_ x: UnavailableSubscripts) {
12071211
_ = self[old: 3] // expected-error {{'subscript(old:)' has been renamed to 'subscript(new:)'}} {{14-17=new}}
12081212
_ = x[old: 3] // expected-error {{'subscript(old:)' has been renamed to 'subscript(new:)'}} {{11-14=new}}
12091213

12101214
_ = self.getValue(old: 3) // expected-error {{'getValue(old:)' has been renamed to 'subscript(new:)'}} {{14-22=[}} {{29-30=]}} {{23-26=new}}
1215+
_ = getValue(old: 3) // expected-error {{'getValue(old:)' has been renamed to 'subscript(new:)'}} {{9-9=self}} {{9-17=[}} {{24-25=]}} {{18-21=new}}
12111216
_ = x.getValue(old: 3) // expected-error {{'getValue(old:)' has been renamed to 'subscript(new:)'}} {{11-19=[}} {{26-27=]}} {{20-23=new}}
12121217

1213-
_ = self[getAValue: 3] // expected-error {{'subscript(getAValue:)' has been renamed to 'getAValue(new:)'}} {{13-14=.getAValue}} {{26-27=)}} {{14-23=new}}
1214-
_ = x[getAValue: 3] // expected-error {{'subscript(getAValue:)' has been renamed to 'getAValue(new:)'}} {{10-11=.getAValue}} {{23-24=)}} {{11-20=new}}
1218+
_ = self[getAValue: 3] // expected-error {{'subscript(getAValue:)' has been renamed to 'getAValue(new:)'}} {{13-14=.getAValue(}} {{26-27=)}} {{14-23=new}}
1219+
_ = x[getAValue: 3] // expected-error {{'subscript(getAValue:)' has been renamed to 'getAValue(new:)'}} {{10-11=.getAValue(}} {{23-24=)}} {{11-20=new}}
12151220

12161221
_ = self[argg1: 3, argg2: 3, argg3: 3] // expected-warning {{'subscript(argg1:argg2:argg3:)' is deprecated: renamed to 'subscript(arg1:arg2:arg3:)'}} // expected-note {{use 'subscript(arg1:arg2:arg3:)' instead}} {{14-19=arg1}} {{24-29=arg2}} {{34-39=arg3}}
12171222
_ = x[argg1: 3, argg2: 3, argg3: 3] // expected-warning {{'subscript(argg1:argg2:argg3:)' is deprecated: renamed to 'subscript(arg1:arg2:arg3:)'}} // expected-note {{use 'subscript(arg1:arg2:arg3:)' instead}} {{11-16=arg1}} {{21-26=arg2}} {{31-36=arg3}}
@@ -1221,5 +1226,8 @@ struct UnavailableSubscripts {
12211226

12221227
_ = self[3, 3, 3] // expected-error {{'subscript(_:_:_:)' has been renamed to 'subscript(arg1:arg2:arg3:)'}} {{14-14=arg1: }} {{17-17=arg2: }} {{20-20=arg3: }}
12231228
_ = x[3, 3, 3] // expected-error {{'subscript(_:_:_:)' has been renamed to 'subscript(arg1:arg2:arg3:)'}} {{11-11=arg1: }} {{14-14=arg2: }} {{17-17=arg3: }}
1229+
1230+
_ = self[to: 3] // expected-warning {{'subscript(to:)' is deprecated: renamed to 'subscriptTo(_:)'}} // expected-note {{use 'subscriptTo(_:)' instead}} {{13-14=.subscriptTo(}} {{19-20=)}} {{14-18=}}
1231+
_ = x[to: 3] // expected-warning {{'subscript(to:)' is deprecated: renamed to 'subscriptTo(_:)'}} // expected-note {{use 'subscriptTo(_:)' instead}} {{10-11=.subscriptTo(}} {{16-17=)}} {{11-15=}}
12241232
}
12251233
}

0 commit comments

Comments
 (0)