Skip to content

Commit 785c44d

Browse files
committed
Don't require ; at the end of a terse lambda
Closes #760
1 parent 32a72fc commit 785c44d

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

source/parse.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7516,15 +7516,18 @@ class parser
75167516
}
75177517

75187518

7519-
// If we're not at a '->' and what follows is an expression-statement,
7520-
// this is a ":(params) expr;" shorthand function syntax
7521-
if (curr().type() != lexeme::Arrow)
7519+
// If we're not at a '->' or 'requires' and what follows is an expression,
7520+
// this is a ":(params) expr" shorthand function syntax
7521+
if (
7522+
curr().type() != lexeme::Arrow
7523+
&& curr() != "requires"
7524+
)
75227525
{
75237526
auto start_pos = pos;
7524-
auto at_an_expression_statement = expression_statement(true) != nullptr;
7527+
auto at_an_expression = expression() != nullptr;
75257528
pos = start_pos; // backtrack no matter what, we're just peeking here
75267529

7527-
if (at_an_expression_statement) {
7530+
if (at_an_expression) {
75287531
n->returns = function_type_node::single_type_id{ std::make_unique<type_id_node>() };
75297532
assert(n->returns.index() == function_type_node::id);
75307533
n->my_decl->terse_no_equals = true;
@@ -7903,7 +7906,7 @@ class parser
79037906
if (n->terse_no_equals)
79047907
{
79057908
n->equal_sign = curr().position();
7906-
n->initializer = statement(/*ignore semicolon_required*/ true, n->equal_sign);
7909+
n->initializer = statement(/*ignore semicolon_required*/ false, n->equal_sign);
79077910
assert( n->initializer && "ICE: should have already validated that there's a valid expression-statement here" );
79087911
}
79097912

0 commit comments

Comments
 (0)