Skip to content

Commit 1af5c85

Browse files
committed
Support #if swift(subminor-version), rdar://problem/28786959 / SR-2908.
1 parent 0ca4b69 commit 1af5c85

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

include/swift/Parse/Parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class Parser {
122122
} InVarOrLetPattern = IVOLP_NotInVarOrLet;
123123

124124
bool InPoundLineEnvironment = false;
125+
bool InPoundIfEnvironment = false;
125126

126127
LocalContext *CurLocalContext = nullptr;
127128

lib/Parse/ParseExpr.cpp

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

14311431
// Don't allow '.<integer literal>' following a numeric literal
1432-
// expression.
1433-
if (Result.isNonNull() && isa<NumberLiteralExpr>(Result.get())) {
1432+
// expression (unless in #if env, for 1.2.3.4 version numbers)
1433+
if (!InPoundIfEnvironment &&
1434+
Result.isNonNull() && isa<NumberLiteralExpr>(Result.get())) {
14341435
diagnose(nameLoc, diag::numeric_literal_numeric_member)
14351436
.highlight(Result.get()->getSourceRange());
14361437
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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@
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)
4847
#endif
4948

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

0 commit comments

Comments
 (0)