Bug 23994 – Compiler fails to derive lambda to be const

Status
NEW
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-06-15T17:12:07Z
Last change time
2024-12-13T19:29:40Z
Assigned to
No Owner
Creator
Andrej Mitrovic
Moved to GitHub: dmd#18175 →

Comments

Comment #0 by andrej.mitrovich — 2023-06-15T17:12:07Z
DMD 2.102.0 ----- module test; void call(void delegate(int i) const cb) { cb(42); } struct C { void callback(int i) const { } } void main() { C c; call(some_int => c.callback(some_int)); } ----- $ dmd test.d > test.d(13): Error: function `test.call(void delegate(int i) const cb)` is not callable using argument types `(void) > test.d(13): cannot pass argument `__lambda2` of type `void` to parameter `void delegate(int i) const cb` Commenting out `const` from both the parameter and the ballback function fixes the issue. Another workaround is to explicitly specify the callback type at the call site: ----- // Works with `const` with the example above call((int some_int) const => c.callback(some_int)); ----- But the compiler should be able to derive this on its own. This workaround also works, where the type is omitted: ----- call((some_int) const => c.callback(some_int)); -----
Comment #1 by robert.schadek — 2024-12-13T19:29:40Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18175 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB