Skip to content

Commit 454aca8

Browse files
committed
---
yaml --- r: 319465 b: refs/heads/master-rebranch c: 3393901 h: refs/heads/master i: 319463: 7c85d04
1 parent 3d84bb0 commit 454aca8

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,4 +1457,4 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-02-a: ddd2b2976aa9bfde5f20fe37f6bd2
14571457
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-03-a: 171cc166f2abeb5ca2a4003700a8a78a108bd300
14581458
refs/heads/benlangmuir-patch-1: baaebaf39d52f3bf36710d4fe40cf212e996b212
14591459
refs/heads/i-do-redeclare: 8c4e6d5de5c1e3f0a2cedccf319df713ea22c48e
1460-
refs/heads/master-rebranch: 5b5abc302c8d887286a3cd6bfd4bc0ca24c287a3
1460+
refs/heads/master-rebranch: 3393901110d65c156db9f4fb6f5a0c023f0a6d80

branches/master-rebranch/include/swift/AST/DiagnosticsParse.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ ERROR(extra_tokens_conditional_compilation_directive,none,
6868
"extra tokens following conditional compilation directive", ())
6969
ERROR(unexpected_rbrace_in_conditional_compilation_block,none,
7070
"unexpected '}' in conditional compilation block", ())
71+
ERROR(unexpected_if_following_else_compilation_directive,none,
72+
"unexpected 'if' keyword following '#else' conditional compilation "
73+
"directive; did you mean '#elseif'?",
74+
())
7175

7276
ERROR(pound_diagnostic_expected_string,none,
7377
"expected string literal in %select{#warning|#error}0 directive",(bool))

branches/master-rebranch/lib/Parse/ParseIfConfig.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,12 @@ ParserResult<IfConfigDecl> Parser::parseIfConfig(
595595
Expr *Condition = nullptr;
596596
bool isActive = false;
597597

598+
if (!Tok.isAtStartOfLine() && isElse && Tok.is(tok::kw_if)) {
599+
diagnose(Tok, diag::unexpected_if_following_else_compilation_directive)
600+
.fixItReplace(SourceRange(ClauseLoc, consumeToken()), "#elseif");
601+
isElse = false;
602+
}
603+
598604
// Parse the condition. Evaluate it to determine the active
599605
// clause unless we're doing a parse-only pass.
600606
if (isElse) {

branches/master-rebranch/test/Parse/ConditionalCompilation/basicParseErrors.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,14 @@ fn_k()
138138
func undefinedFunc() // ignored.
139139
#endif
140140
undefinedFunc() // expected-error {{use of unresolved identifier 'undefinedFunc'}}
141+
142+
#if FOO
143+
#else if BAR
144+
// expected-error@-1 {{unexpected 'if' keyword following '#else' conditional compilation directive; did you mean '#elseif'?}} {{1-9=#elseif}}
145+
#else
146+
#endif
147+
148+
#if FOO
149+
#else
150+
if true {}
151+
#endif // OK

0 commit comments

Comments
 (0)