Skip to content

Rdar 28786959 3.0 branch if swift 3 digit version #5482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/swift/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class Parser {
bool ArgumentIsParameter = false;

bool InPoundLineEnvironment = false;
bool InPoundIfEnvironment = false;

LocalContext *CurLocalContext = nullptr;

Expand Down
11 changes: 7 additions & 4 deletions lib/Basic/Version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,18 @@ bool operator>=(const class Version &lhs,
if (lhs.empty())
return true;

auto n = std::min(lhs.size(), rhs.size());
auto n = std::max(lhs.size(), rhs.size());

for (size_t i = 0; i < n; ++i) {
if (lhs[i] < rhs[i])
auto lv = i < lhs.size() ? lhs[i] : 0;
auto rv = i < rhs.size() ? rhs[i] : 0;
if (lv < rv)
return false;
else if (lhs[i] > rhs[i])
else if (lv > rv)
return true;
}
return lhs.size() >= rhs.size();
// Equality
return true;
}

std::pair<unsigned, unsigned> getSwiftNumericVersion() {
Expand Down
5 changes: 3 additions & 2 deletions lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1430,8 +1430,9 @@ ParserResult<Expr> Parser::parseExprPostfix(Diag<> ID, bool isExprBasic) {
SourceLoc nameLoc = consumeToken(tok::integer_literal);

// Don't allow '.<integer literal>' following a numeric literal
// expression.
if (Result.isNonNull() && isa<NumberLiteralExpr>(Result.get())) {
// expression (unless in #if env, for 1.2.3.4 version numbers)
if (!InPoundIfEnvironment &&
Result.isNonNull() && isa<NumberLiteralExpr>(Result.get())) {
diagnose(nameLoc, diag::numeric_literal_numeric_member)
.highlight(Result.get()->getSourceRange());
continue;
Expand Down
2 changes: 1 addition & 1 deletion lib/Parse/ParseStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1759,7 +1759,7 @@ Parser::evaluateConditionalCompilationExpr(Expr *condition) {
ParserResult<Stmt> Parser::parseStmtIfConfig(BraceItemListKind Kind) {
StructureMarkerRAII ParsingDecl(*this, Tok.getLoc(),
StructureMarkerKind::IfConfig);

llvm::SaveAndRestore<bool> S(InPoundIfEnvironment, true);
ConditionalCompilationExprState ConfigState;
bool foundActive = false;
SmallVector<IfConfigStmtClause, 4> Clauses;
Expand Down
12 changes: 10 additions & 2 deletions test/Parse/ConditionalCompilation/language_version.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,16 @@
#if swift("") // expected-error {{unexpected platform condition argument: expected a unary comparison, such as '>=2.2'}}
#endif

// We won't expect three version components to work for now.
#if swift(>=2.2.1) // expected-error {{expected named member of numeric literal}}
#if swift(>=2.2.1)
#endif

// Check that an extra .0 doesn't make a version "bigger"; NB this test only
// tests the fix on 3.0.1, but that's the swift version the fix was backported
// to. On master, the fix is tested by language_version_explicit.swift
#if swift(>=3.0.1.0)
#else
// This shouldn't emit any diagnostics.
asdf asdf asdf asdf
#endif

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