Skip to content

Commit 817effa

Browse files
ntreldlang-bot
authored andcommitted
[spec] Describe parameter-less function literal
Part of issue 21619. Also split short syntax section in two.
1 parent 24559e7 commit 817effa

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

spec/expression.dd

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,10 +2327,23 @@ $(H4 $(LNAME2 lambda-return-type, Return Type Inference))
23272327
---
23282328
)
23292329

2330-
$(H4 $(LNAME2 lambda-short-syntax, Short Syntax))
2330+
$(H4 $(LNAME2 lambda-short-syntax, Nullary Short Syntax))
23312331

2332-
$(P Anonymous delegates can behave like arbitrary statement literals.
2333-
For example, here an arbitrary statement is executed by a loop:)
2332+
$(P *Parameters* can be omitted completely for a function literal
2333+
when there is a *BlockStatement* function body.)
2334+
2335+
$(NOTE This form is not allowed to be immediately called as an *ExpressionStatement*,
2336+
because it would require arbitrary lookahead to distinguish it from a *BlockStatement*.)
2337+
2338+
---
2339+
auto f = { writeln("hi"); }; // OK, f has type `void function()`
2340+
f();
2341+
{ writeln("hi"); }(); // error
2342+
() { writeln("hi"); }(); // OK
2343+
---
2344+
2345+
$(PANEL Anonymous delegates can behave like arbitrary statement literals.
2346+
For example, here an arbitrary statement is executed by a loop:
23342347

23352348
$(SPEC_RUNNABLE_EXAMPLE_RUN
23362349
-------------
@@ -2351,6 +2364,9 @@ $(H4 $(LNAME2 lambda-short-syntax, Short Syntax))
23512364
}
23522365
-------------
23532366
)
2367+
)
2368+
2369+
$(H4 $(LNAME2 lambda-short-body, Shortened Body Syntax))
23542370

23552371
$(P The syntax $(D => AssignExpression) is equivalent to $(D { return AssignExpression; }).)
23562372

0 commit comments

Comments
 (0)