Skip to content

Commit 3b42894

Browse files
committed
[Parse] Fix parsing three-version-components in #if
* Narrow allowance of 3+ components numeric literal to condition part of the directive. * Allow 3+ components in '#if' directive in decl list position as well.
1 parent cfe742d commit 3b42894

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3016,6 +3016,7 @@ ParserResult<IfConfigDecl> Parser::parseDeclIfConfig(ParseDeclOptions Flags) {
30163016
ConfigState.setConditionActive(!foundActive);
30173017
} else {
30183018
// Evaluate the condition.
3019+
llvm::SaveAndRestore<bool> S(InPoundIfEnvironment, true);
30193020
ParserResult<Expr> Result = parseExprSequence(diag::expected_expr,
30203021
/*isBasic*/true,
30213022
/*isForDirective*/true);

lib/Parse/ParseStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1771,7 +1771,6 @@ Parser::classifyConditionalCompilationExpr(Expr *condition,
17711771
ParserResult<Stmt> Parser::parseStmtIfConfig(BraceItemListKind Kind) {
17721772
StructureMarkerRAII ParsingDecl(*this, Tok.getLoc(),
17731773
StructureMarkerKind::IfConfig);
1774-
llvm::SaveAndRestore<bool> S(InPoundIfEnvironment, true);
17751774
SmallVector<IfConfigStmtClause, 4> Clauses;
17761775

17771776
bool foundActive = false;
@@ -1785,6 +1784,7 @@ ParserResult<Stmt> Parser::parseStmtIfConfig(BraceItemListKind Kind) {
17851784
ConfigState.setConditionActive(!foundActive);
17861785
} else {
17871786
// Evaluate the condition.
1787+
llvm::SaveAndRestore<bool> S(InPoundIfEnvironment, true);
17881788
ParserResult<Expr> Result = parseExprSequence(diag::expected_expr,
17891789
/*basic*/true,
17901790
/*isForDirective*/true);

test/Parse/ConditionalCompilation/language_version.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,15 @@
4444
#endif
4545

4646
#if swift(>=2.2.1)
47+
_ = 2.2.1 // expected-error {{expected named member of numeric literal}}
4748
#endif
4849

50+
class C {
51+
#if swift(>=2.2.1)
52+
let val = 2.2.1 // expected-error {{expected named member of numeric literal}}
53+
#endif
54+
}
55+
4956
#if swift(>=2.0, *) // expected-error {{expected only one argument to platform condition}}
5057
#endif
5158

0 commit comments

Comments
 (0)