Skip to content

Commit f702272

Browse files
authored
Merge pull request #64734 from tristanlabelle/fix-available-attribute-out-of-bounds-access
Fix out-of-bounds when providing fixits for the @available attribute.
2 parents 47bf147 + f555154 commit f702272

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,11 +2508,11 @@ static void fixItAvailableAttrRename(InFlightDiagnostic &diag,
25082508
auto I = argumentLabelIDs.begin();
25092509

25102510
auto updateLabelsForArg = [&](Expr *expr) -> bool {
2511+
if (I == argumentLabelIDs.end())
2512+
return true;
2513+
25112514
if (isa<DefaultArgumentExpr>(expr)) {
25122515
// Defaulted: remove param label of it.
2513-
if (I == argumentLabelIDs.end())
2514-
return true;
2515-
25162516
I = argumentLabelIDs.erase(I);
25172517
return false;
25182518
}
@@ -2539,9 +2539,6 @@ static void fixItAvailableAttrRename(InFlightDiagnostic &diag,
25392539
}
25402540

25412541
// Normal: Just advance.
2542-
if (I == argumentLabelIDs.end())
2543-
return true;
2544-
25452542
++I;
25462543
return false;
25472544
};

test/attr/attr_availability_unavailability.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,14 @@ func testUnavailableExpandAllElsePaths() {
5858
} else {
5959
foo()
6060
}
61-
}
61+
}
62+
63+
func log(message: String) {}
64+
65+
@available(*, unavailable, renamed: "log(message:)")
66+
func log(format: String, _ args: Any...) { fatalError() } // expected-note {{'log(format:_:)' has been explicitly marked unavailable here}}
67+
68+
// Regression test for https://github.com/apple/swift/issues/64694
69+
func testUnavailableRenamedFromVariadicDoesntAssert() {
70+
log(format: "") // expected-error{{'log(format:_:)' has been renamed to 'log(message:)'}}
71+
}

0 commit comments

Comments
 (0)