Skip to content

[Parse] getLineNumber before parsing the closure #15178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3089,6 +3089,12 @@ ParserStatus Parser::parseExprList(tok leftTok, tok rightTok,
ParserResult<Expr> Parser::parseTrailingClosure(SourceRange calleeRange) {
SourceLoc braceLoc = Tok.getLoc();

// Record the line numbers for the diagnostics below.
// Note that *do not* move this to after 'parseExprClosure()' it slows down
// 'getLineNumber()' call because of cache in SourceMgr.
auto origLine = SourceMgr.getLineNumber(calleeRange.End);
auto braceLine = SourceMgr.getLineNumber(braceLoc);

// Parse the closure.
ParserResult<Expr> closure = parseExprClosure();
if (closure.isNull())
Expand All @@ -3097,8 +3103,6 @@ ParserResult<Expr> Parser::parseTrailingClosure(SourceRange calleeRange) {
// Warn if the trailing closure is separated from its callee by more than
// one line. A single-line separation is acceptable for a trailing closure
// call, and will be diagnosed later only if the call fails to typecheck.
auto origLine = SourceMgr.getLineNumber(calleeRange.End);
auto braceLine = SourceMgr.getLineNumber(braceLoc);
if (braceLine > origLine + 1) {
diagnose(braceLoc, diag::trailing_closure_after_newlines);
diagnose(calleeRange.Start, diag::trailing_closure_callee_here);
Expand Down