Skip to content

Commit 3c260bb

Browse files
author
ematejska
authored
Merge pull request #5482 from graydon/rdar-28786959-3.0-branch-if-swift-3-digit-version
Rdar 28786959 3.0 branch if swift 3 digit version
2 parents 436e551 + 113cbe0 commit 3c260bb

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

include/swift/Parse/Parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class Parser {
128128
bool ArgumentIsParameter = false;
129129

130130
bool InPoundLineEnvironment = false;
131+
bool InPoundIfEnvironment = false;
131132

132133
LocalContext *CurLocalContext = nullptr;
133134

lib/Basic/Version.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,18 @@ bool operator>=(const class Version &lhs,
293293
if (lhs.empty())
294294
return true;
295295

296-
auto n = std::min(lhs.size(), rhs.size());
296+
auto n = std::max(lhs.size(), rhs.size());
297297

298298
for (size_t i = 0; i < n; ++i) {
299-
if (lhs[i] < rhs[i])
299+
auto lv = i < lhs.size() ? lhs[i] : 0;
300+
auto rv = i < rhs.size() ? rhs[i] : 0;
301+
if (lv < rv)
300302
return false;
301-
else if (lhs[i] > rhs[i])
303+
else if (lv > rv)
302304
return true;
303305
}
304-
return lhs.size() >= rhs.size();
306+
// Equality
307+
return true;
305308
}
306309

307310
std::pair<unsigned, unsigned> getSwiftNumericVersion() {

lib/Parse/ParseExpr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,8 +1430,9 @@ ParserResult<Expr> Parser::parseExprPostfix(Diag<> ID, bool isExprBasic) {
14301430
SourceLoc nameLoc = consumeToken(tok::integer_literal);
14311431

14321432
// Don't allow '.<integer literal>' following a numeric literal
1433-
// expression.
1434-
if (Result.isNonNull() && isa<NumberLiteralExpr>(Result.get())) {
1433+
// expression (unless in #if env, for 1.2.3.4 version numbers)
1434+
if (!InPoundIfEnvironment &&
1435+
Result.isNonNull() && isa<NumberLiteralExpr>(Result.get())) {
14351436
diagnose(nameLoc, diag::numeric_literal_numeric_member)
14361437
.highlight(Result.get()->getSourceRange());
14371438
continue;

lib/Parse/ParseStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1759,7 +1759,7 @@ Parser::evaluateConditionalCompilationExpr(Expr *condition) {
17591759
ParserResult<Stmt> Parser::parseStmtIfConfig(BraceItemListKind Kind) {
17601760
StructureMarkerRAII ParsingDecl(*this, Tok.getLoc(),
17611761
StructureMarkerKind::IfConfig);
1762-
1762+
llvm::SaveAndRestore<bool> S(InPoundIfEnvironment, true);
17631763
ConditionalCompilationExprState ConfigState;
17641764
bool foundActive = false;
17651765
SmallVector<IfConfigStmtClause, 4> Clauses;

test/Parse/ConditionalCompilation/language_version.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,16 @@
4343
#if swift("") // expected-error {{unexpected platform condition argument: expected a unary comparison, such as '>=2.2'}}
4444
#endif
4545

46-
// We won't expect three version components to work for now.
47-
#if swift(>=2.2.1) // expected-error {{expected named member of numeric literal}}
46+
#if swift(>=2.2.1)
47+
#endif
48+
49+
// Check that an extra .0 doesn't make a version "bigger"; NB this test only
50+
// tests the fix on 3.0.1, but that's the swift version the fix was backported
51+
// to. On master, the fix is tested by language_version_explicit.swift
52+
#if swift(>=3.0.1.0)
53+
#else
54+
// This shouldn't emit any diagnostics.
55+
asdf asdf asdf asdf
4856
#endif
4957

5058
#if swift(>=2.0, *) // expected-error {{expected only one argument to platform condition}}

0 commit comments

Comments
 (0)