Skip to content

Commit b379097

Browse files
committed
[Type checker] Fix assertion diagnosting a rename with a different # of arguments.
1 parent d1c5663 commit b379097

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,12 +1775,15 @@ static void fixItAvailableAttrRename(InFlightDiagnostic &diag,
17751775
// argumentLabelIDs = {"w", "x", "", "", "z"}
17761776
auto I = argumentLabelIDs.begin();
17771777

1778-
auto updateLabelsForArg = [&](Expr *expr) {
1778+
auto updateLabelsForArg = [&](Expr *expr) -> bool {
17791779
if (isa<DefaultArgumentExpr>(expr) ||
17801780
isa<CallerDefaultArgumentExpr>(expr)) {
17811781
// Defaulted: remove param label of it.
1782+
if (I == argumentLabelIDs.end())
1783+
return true;
1784+
17821785
I = argumentLabelIDs.erase(I);
1783-
return;
1786+
return false;
17841787
}
17851788

17861789
if (auto *varargExpr = dyn_cast<VarargExpansionExpr>(expr)) {
@@ -1800,19 +1803,26 @@ static void fixItAvailableAttrRename(InFlightDiagnostic &diag,
18001803
I = argumentLabelIDs.insert(I, variadicArgsNum, Identifier());
18011804
I += variadicArgsNum;
18021805
}
1803-
return;
1806+
return false;
18041807
}
18051808
}
18061809

18071810
// Normal: Just advance.
1811+
if (I == argumentLabelIDs.end())
1812+
return true;
1813+
18081814
++I;
1815+
return false;
18091816
};
18101817

18111818
if (auto *parenExpr = dyn_cast<ParenExpr>(argExpr)) {
1812-
updateLabelsForArg(parenExpr->getSubExpr());
1819+
if (updateLabelsForArg(parenExpr->getSubExpr()))
1820+
return;
18131821
} else {
1814-
for (auto *arg : cast<TupleExpr>(argExpr)->getElements())
1815-
updateLabelsForArg(arg);
1822+
for (auto *arg : cast<TupleExpr>(argExpr)->getElements()) {
1823+
if (updateLabelsForArg(arg))
1824+
return;
1825+
}
18161826
}
18171827

18181828
if (argumentLabelIDs.size() != argList.args.size()) {

test/attr/attr_availability.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,3 +1100,16 @@ func unavailableFunc(_ arg: UnavailableProto) -> UnavailableProto {}
11001100
struct S {
11011101
var a: UnavailableProto
11021102
}
1103+
1104+
// Bad rename.
1105+
struct BadRename {
1106+
@available(*, deprecated, renamed: "init(range:step:)")
1107+
init(from: Int, to: Int, step: Int = 1) { }
1108+
1109+
init(range: Range<Int>, step: Int) { }
1110+
}
1111+
1112+
func testBadRename() {
1113+
_ = BadRename(from: 5, to: 17) // expected-warning{{'init(from:to:step:)' is deprecated: replaced by 'init(range:step:)'}}
1114+
// expected-note@-1{{use 'init(range:step:)' instead}}
1115+
}

0 commit comments

Comments
 (0)