Bug 23918 – Lambdas declared as "function" should be static and not have a context

Status
NEW
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-05-12T21:21:41Z
Last change time
2024-12-13T19:28:57Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
Vladimir Panteleev
Moved to GitHub: dmd#20280 →

Comments

Comment #0 by dlang-bugzilla — 2023-05-12T21:21:41Z
/////////////////// test.d /////////////////// struct BobsContext { void bobWhoAlreadyHasAContext(alias fun)() { fun(1); } } void main() { BobsContext b; // Works: { void fun(X)(X x) {} b.bobWhoAlreadyHasAContext!fun(); } // Doesn't work: { alias fun = function (x) {}; b.bobWhoAlreadyHasAContext!fun(); } } ////////////////////////////////////////////// (DMD currently produces the "function requires a dual-context" deprecation) Leaving aside the question of why lambdas don't have their need for context auto-detected like normal template functions... if the user writes the keyword "function", that should effectively make the lambda static and not require a context. If this somehow ends up too much of a breaking change... the "static" keyword is currently not accepted in lambda / anonymous function literals, but it could be.
Comment #1 by robert.schadek — 2024-12-13T19:28:57Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20280 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB