Bug 21377 – Unclear error message "delegate __lambda cannot be struct members"

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-11-11T03:28:31Z
Last change time
2024-12-13T19:12:38Z
Assigned to
No Owner
Creator
bradley.chatha
Moved to GitHub: dmd#19818 →

Comments

Comment #0 by bradley.chatha — 2020-11-11T03:28:31Z
The following code produces an error (possible bug?) with a very confusing and unclear message: struct S { bool delegate(string) f; } @S(str => true) // VALID int a; S s = S(str => true); // VALID struct S2 { @S(str => false) // INVALID int a; } // Error: delegate onlineapp.S2.__lambda2 cannot be struct members
Comment #1 by bradley.chatha — 2020-11-11T03:32:25Z
Relevant quote from the forums: "The actual problem is that the compiler isn't able to figure out the type of the lambda you've provided. If you change the argument to `(string str)`, it'll work. The real question is, why does type inference fail for the UDA when it works for the normal constructor call?"
Comment #2 by bradley.chatha — 2021-01-28T17:28:41Z
I have a sneaking suspicion that this may be slightly related to one of the underlying problems for https://issues.dlang.org/show_bug.cgi?id=21496 which is where templated types that contain a template parameter into a struct member, will then implicitly become embedded within the struct itself. So the anonymous lambda inside of `S2` in the example is being "falsely" embedded into `S2` which is causing this error, likely because the lambda is lowered into a form of template.
Comment #3 by robert.schadek — 2024-12-13T19:12:38Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19818 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB