Skip to content

Commit 03d6f25

Browse files
committed
Fix crash parsing #available with missing version.
In a multipart #available spec list, don't attempt to look at the SpecResult for the previous part if there wasn't one (a missing version number for example). Added a test case that asserted before this change.
1 parent f2e8e0a commit 03d6f25

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/Parse/ParseStmt.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,8 @@ Parser::parseAvailabilitySpecList(SmallVectorImpl<AvailabilitySpec *> &Specs) {
11231123
// also in the shorthand syntax and provide a more specific diagnostic if
11241124
// that's not the case.
11251125
if (Tok.isIdentifierOrUnderscore() &&
1126-
!peekToken().isAny(tok::integer_literal, tok::floating_literal)) {
1126+
!peekToken().isAny(tok::integer_literal, tok::floating_literal) &&
1127+
!Specs.empty()) {
11271128
auto Text = Tok.getText();
11281129
if (Text == "deprecated" || Text == "renamed" || Text == "introduced" ||
11291130
Text == "message" || Text == "obsoleted" || Text == "unavailable") {

test/Parse/availability_query.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ if #available(OSX 10.51, iOS 8.0) { } // expected-error {{must handle potential
5555
if #available(iOS 8.0, *) {
5656
}
5757

58+
if #available(iOSApplicationExtension, unavailable) { // expected-error 2{{expected version number}}
59+
}
60+
5861
// Want to make sure we can parse this. Perhaps we should not let this validate, though.
5962
if #available(*) {
6063
}

0 commit comments

Comments
 (0)