www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21697] New: Absurd limitations when passing lambda as alias

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 puremagic.com
          Reporter: deadalnix 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!

--
Mar 09