[Issue 21697] New: Absurd limitations when passing lambda as alias parameter and bad error message
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Mar 10 01:23:30 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=21697
Issue ID: 21697
Summary: Absurd limitations when passing lambda as alias
parameter and bad error message
Product: D
Version: D2
Hardware: x86
OS: All
Status: NEW
Severity: major
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: deadalnix at gmail.com
See sample code:
module test;
struct S {
void foo() {}
void run(alias f)() { f(); }
void bar() {
// OK
run!foo();
// OK
void bar() {
foo();
}
run!bar();
// Error
run!(() { foo(); })();
}
}
The limitation of the 3rd syntax seems rather arbitrary. The error message is
also rather inscrutable for someone who's not very familiar with D:
test.d(5): Error: function test.S.bar.run!(delegate () @system
{
this.foo();
}
).run cannot get frame pointer to test.S.bar.__lambda2
My interpretation of what is happening is that the lambda gets instantiated at
the call site, and dmd assumes it needs a context when it doesn't. Note that
the error message doesn't refers to the line at which the error occurs at all!
--
More information about the Digitalmars-d-bugs
mailing list