Bug 13451 – Lambda syntax with explicit return type not documented

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-09-09T23:32:00Z
Last change time
2014-09-23T23:38:04Z
Keywords
pull, spec
Assigned to
nobody
Creator
briancschott
Blocks
10233

Comments

Comment #0 by briancschott — 2014-09-09T23:32:04Z
--- fp = function int(int a) => a; --- This code is accepted by DMD but cannot be produced by the grammar: FunctionLiteral: function Type(opt) ParameterAttributes(opt) FunctionBody delegate Type(opt) ParameterAttributes(opt) FunctionBody ParameterAttributes FunctionBody FunctionBody Lambda ParameterAttributes: Parameters Parameters FunctionAttributes Lambda: Identifier => AssignExpression function(opt) ParameterAttributes => AssignExpression delegate(opt) ParameterAttributes => AssignExpression
Comment #1 by hsteoh — 2014-09-09T23:37:51Z
I had no idea this syntax was supported. Is it intentional, or is it an oversight in the implementation?
Comment #2 by briancschott — 2014-09-09T23:41:57Z
https://github.com/D-Programming-Language/dmd/blob/master/test/runnable/funclit.d#L258 I would not be surprised if it started off as an oversight and was then added to the test suite. We should never break the promises we never made, right?
Comment #3 by jakobovrum — 2014-09-09T23:44:19Z
(In reply to hsteoh from comment #1) > I had no idea this syntax was supported. Is it intentional, or is it an > oversight in the implementation? It's a hold-over from the other function literal syntax: auto fp = function int(int a) { return a; }; It's just as useful whether it's using lambdas or the old syntax, so I suggest we reconcile the grammar with DMD in this case.
Comment #4 by k.hara.pg — 2014-09-19T00:26:10Z
(In reply to briancschott from comment #0) > --- > fp = function int(int a) => a; > --- When I cleaned up parser code for lambdas, the syntax was intentional as that is a combination of: - the keyword "function" for function literals - optional return type specification - parameter list - lambda style function literal body ("=>" with one AssignExpression) So, I'd fix the grammar to fit accepted code by dmd, like follows. Lambda: function Type(opt) ParameterAttributes => AssignExpression delegate Type(opt) ParameterAttributes => AssignExpression ParameterAttributes => AssignExpression Identifier => AssignExpression
Comment #5 by k.hara.pg — 2014-09-19T03:09:55Z
Comment #6 by github-bugzilla — 2014-09-23T23:38:04Z
Commits pushed to master at https://github.com/D-Programming-Language/dlang.org https://github.com/D-Programming-Language/dlang.org/commit/54a1e7e04e9576f3c08bf41ac3fad721366eee60 fix Issue 13451 - Lambda syntax with explicit return type not documented https://github.com/D-Programming-Language/dlang.org/commit/d4c0a53c2b123e46bfc9dba2ec75b608f6f44769 Merge pull request #656 from 9rnsr/fix13451 Issue 13451 - Lambda syntax with explicit return type not documented