Bug 16001 – Lambda syntax: forbid use with FunctionLiteralBody: (x) => {assert(x);}

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-05-07T16:28:20Z
Last change time
2021-07-09T00:37:31Z
Keywords
pull
Assigned to
No Owner
Creator
sigod

Comments

Comment #0 by sigod.mail — 2016-05-07T16:28:20Z
As discussed here: https://forum.dlang.org/post/[email protected] It's very common for people from other languages to write something like list.each!(x => { /* use x */ }); Which, of course, doesn't work as expected.
Comment #1 by xinok — 2016-05-13T01:53:09Z
Comment #2 by dlang-bot — 2021-05-18T13:33:16Z
@adamdruppe updated dlang/dmd pull request #12528 "deprecate the common mistake people make coming from Javascript and C#" fixing this issue: - fix issue 16001 A common mistake D users make - sometimes even experienced D users - is to use `() => { multi; line; lambda; }`. This syntax is common in several other languages, including D's syntax relatives of Javascript and C#, but in D, it is completely different (yet frequently still compiles!) and leaves users puzzled why their code seemingly does nothing. This deprecation is aimed very specifically at that syntax rather than the semantic construct to warn them that they're doing it wrong and it offers easy suggestions to clarify their intent with existing D syntax, similarly to how `if(a = x)` and switch fallthrough was deemed more error-prone than it was worth given the easy and clear alternatives. https://github.com/dlang/dmd/pull/12528
Comment #3 by dlang-bot — 2021-05-26T23:47:28Z
dlang/dmd pull request #12528 "Fix 16001 - forbid lambda syntax followed by FunctionLiteralBody" was merged into master: - 7e9c5705e15fc980bd92f3752377ba75f2e73d12 by Adam D. Ruppe: fix issue 16001 - forbid lambda syntax followed by FunctionLiteralBody A common mistake D users make - sometimes even experienced D users - is to use `() => { multi; line; lambda; }`. This syntax is common in several other languages, including D's syntax relatives of Javascript and C#, but in D, it is completely different (yet frequently still compiles!) and leaves users puzzled why their code seemingly does nothing. This deprecation is aimed very specifically at that syntax rather than the semantic construct to warn them that they're doing it wrong and it offers easy suggestions to clarify their intent with existing D syntax, similarly to how `if(a = x)` and switch fallthrough was deemed more error-prone than it was worth given the easy and clear alternatives. https://github.com/dlang/dmd/pull/12528
Comment #4 by dkorpel — 2021-07-09T00:37:31Z
*** Issue 17951 has been marked as a duplicate of this issue. ***