Skip to content

Commit b2d549e

Browse files
committed
[Parse][Swift3] Add a warning for unsupported conditional compiliation expression
1 parent b950f06 commit b2d549e

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,9 @@ ERROR(unexpected_version_comparison_operator,none,
13561356
())
13571357
ERROR(unsupported_conditional_compilation_expression_type,none,
13581358
"invalid conditional compilation expression", ())
1359+
WARNING(swift3_unsupported_conditional_compilation_expression_type,none,
1360+
"ignoring invalid conditional compilation expression, "
1361+
"which will be rejected in future version of Swift", ())
13591362
ERROR(unsupported_conditional_compilation_integer,none,
13601363
"'%0' is not a valid conditional compilation expression, use '%1'",
13611364
(StringRef, StringRef))

lib/Parse/ParseStmt.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1584,7 +1584,12 @@ Parser::classifyConditionalCompilationExpr(Expr *condition,
15841584
diag::unsupported_conditional_compilation_expression_type);
15851585
return ConditionalCompilationExprState::error();
15861586
} else {
1587-
// TODO: Emit a warning.
1587+
SourceRange ignoredRange(elements[iOperator]->getLoc(),
1588+
elements[iOperand]->getEndLoc());
1589+
D.diagnose(
1590+
elements[iOperator]->getLoc(),
1591+
diag::swift3_unsupported_conditional_compilation_expression_type)
1592+
.highlight(ignoredRange);
15881593
}
15891594
}
15901595

test/Compatibility/conditional_compiliation_expr.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
#if FOO = false
5+
// expected-warning @-1 {{ignoring invalid conditional compilation expression, which will be rejected in future version of Swift}}
56
undefinedFunc() // expected-error {{use of unresolved identifier 'undefinedFunc'}}
67
#else
78
undefinedFunc() // ignored.
@@ -10,6 +11,7 @@ undefinedFunc() // ignored.
1011
#if false
1112

1213
#elseif !FOO ? false : true
14+
// expected-warning @-1 {{ignoring invalid conditional compilation expression, which will be rejected in future version of Swift}}
1315
undefinedFunc() // ignored.
1416
#else
1517
undefinedFunc() // expected-error {{use of unresolved identifier 'undefinedFunc'}}

0 commit comments

Comments
 (0)