Skip to content

Commit 4630031

Browse files
committed
add warning that 'await' will become contextual keyword
1 parent 698a0a3 commit 4630031

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,9 @@ NOTE(super_in_closure_with_capture_here,none,
12241224
"'self' explicitly captured here", ())
12251225

12261226
ERROR(try_before_await,none, "'await' must precede 'try'", ())
1227+
WARNING(warn_await_keyword,none,
1228+
"future versions of Swift reserve the word 'await'; "
1229+
"if this name is unavoidable, use backticks to escape it", ())
12271230

12281231
// Tuples and parenthesized expressions
12291232
ERROR(expected_expr_in_expr_list,none,

lib/Parse/ParseExpr.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -399,16 +399,22 @@ ParserResult<Expr> Parser::parseExprSequenceElement(Diag<> message,
399399
SyntaxParsingContext ElementContext(SyntaxContext,
400400
SyntaxContextKind::Expr);
401401

402-
if (shouldParseExperimentalConcurrency() && Tok.isContextualKeyword("await")) {
403-
SourceLoc awaitLoc = consumeToken();
404-
ParserResult<Expr> sub =
405-
parseExprSequenceElement(diag::expected_expr_after_await, isExprBasic);
406-
if (!sub.hasCodeCompletion() && !sub.isNull()) {
407-
ElementContext.setCreateSyntax(SyntaxKind::AwaitExpr);
408-
sub = makeParserResult(new (Context) AwaitExpr(awaitLoc, sub.get()));
409-
}
402+
if (Tok.isContextualKeyword("await")) {
403+
if (shouldParseExperimentalConcurrency()) {
404+
SourceLoc awaitLoc = consumeToken();
405+
ParserResult<Expr> sub =
406+
parseExprSequenceElement(diag::expected_expr_after_await, isExprBasic);
407+
if (!sub.hasCodeCompletion() && !sub.isNull()) {
408+
ElementContext.setCreateSyntax(SyntaxKind::AwaitExpr);
409+
sub = makeParserResult(new (Context) AwaitExpr(awaitLoc, sub.get()));
410+
}
410411

411-
return sub;
412+
return sub;
413+
} else {
414+
// warn that future versions of Swift will parse this token differently.
415+
diagnose(Tok.getLoc(), diag::warn_await_keyword)
416+
.fixItReplace(Tok.getLoc(), "`await`");
417+
}
412418
}
413419

414420
SourceLoc tryLoc;

0 commit comments

Comments
 (0)