Skip to content

Commit 88f2632

Browse files
committed
Allow trailing closures with a line break before '{'.
Swift SVN r19322
1 parent ab14eeb commit 88f2632

File tree

5 files changed

+11
-14
lines changed

5 files changed

+11
-14
lines changed

include/swift/Parse/Token.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,6 @@ class Token {
166166
return !isAtStartOfLine() && Kind == tok::l_square;
167167
}
168168

169-
/// True if the token is an l_brace token that does not start a new line.
170-
bool isFollowingLBrace() const {
171-
return !isAtStartOfLine() && Kind == tok::l_brace;
172-
}
173-
174169
/// True if the token is any keyword.
175170
bool isKeyword() const {
176171
switch (Kind) {

lib/Parse/ParseExpr.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ ParserResult<Expr> Parser::parseExprNew() {
491491

492492
// Check for an initialization closure.
493493
Expr *constructExpr = nullptr;
494-
if (Tok.isFollowingLBrace()) {
494+
if (Tok.is(tok::l_brace)) {
495495
ParserResult<Expr> construction = parseExprClosure();
496496
if (construction.hasCodeCompletion())
497497
return construction;
@@ -912,7 +912,7 @@ ParserResult<Expr> Parser::parseExprPostfix(Diag<> ID, bool isExprBasic) {
912912
consumeToken(tok::period_prefix);
913913
IsPeriod = peekToken().isFollowingLParen() ||
914914
peekToken().isFollowingLSquare() ||
915-
peekToken().isFollowingLBrace();
915+
peekToken().is(tok::l_brace);
916916
}
917917
if (consumeIf(tok::period) || (IsPeriod && consumeIf(tok::period_prefix))) {
918918
// Non-identifier cases.
@@ -1125,7 +1125,7 @@ ParserResult<Expr> Parser::parseExprPostfix(Diag<> ID, bool isExprBasic) {
11251125
}
11261126

11271127
// Check for a trailing closure, if allowed.
1128-
if (!isExprBasic && Tok.isFollowingLBrace() &&
1128+
if (!isExprBasic && Tok.is(tok::l_brace) &&
11291129
!isStartOfGetSetAccessor(*this)) {
11301130
// Parse the closure.
11311131
ParserResult<Expr> closure = parseExprClosure();
@@ -1154,7 +1154,7 @@ ParserResult<Expr> Parser::parseExprPostfix(Diag<> ID, bool isExprBasic) {
11541154

11551155
// We only allow a single trailing closure on a call. This could be
11561156
// generalized in the future, but needs further design.
1157-
if (Tok.isFollowingLBrace()) break;
1157+
if (Tok.is(tok::l_brace)) break;
11581158
continue;
11591159
}
11601160

test/Interpreter/arrays.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ println()
5656
// CHECK: dead
5757
// CHECK: dead
5858
// CHECK: dead
59-
{ [Canary(), Canary(), Canary()] }()
59+
_ = { [Canary(), Canary(), Canary()] }()
6060

6161
// Create an array of (String, Bool) pairs. <rdar://problem/16916422>
6262
do {

test/Parse/toplevel_library_invalid.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
println("a"); // expected-error {{expressions are not allowed at the top level}}
44
println("a"); // expected-error {{expressions are not allowed at the top level}}
55
// Make sure we don't crash on closures at the top level
6-
{ } // expected-error {{expressions are not allowed at the top level}} expected-error {{braced block of statements}}
7-
{ 5 }() // expected-error {{expressions are not allowed at the top level}}
6+
({ }) // expected-error {{expressions are not allowed at the top level}}
7+
({ 5 }()) // expected-error {{expressions are not allowed at the top level}}
88

99
// FIXME: Too many errors for this.
1010
for i // expected-error 2 {{expected ';' in 'for' statement}}

test/expr/closure/trailing.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ var a = C().map {$0 + 1}.filter {$0 % 3 == 0}
4444
var b = C().map {$0 + 1}
4545
.filter {$0 % 3 == 0}
4646

47-
48-
47+
var c = C().map
48+
{
49+
$0 + 1
50+
}
4951

5052

5153
// Calls with multiple trailing closures should be rejected until we have time

0 commit comments

Comments
 (0)