www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20304] New: Implement variadic parameters for lambdas

https://issues.dlang.org/show_bug.cgi?id=20304

          Issue ID: 20304
           Summary: Implement variadic parameters for lambdas
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: maxsamukha gmail.com

I do not know whether this should be an enhancement or bug. Variadic parameters
for lambdas are unspecified. The syntax is accepted, but any attempt to
instantiate such a lambda with multiple arguments results in a semantic error.

alias foo = (a...) {
};

void main() {
    foo(1, 2);
}

onlineapp.d(5): Error: template onlineapp.__lambda4 cannot deduce function from
argument types !()(int, int), candidates are:
onlineapp.d(1):        onlineapp.__lambda4

https://run.dlang.io/is/lByBjC


Why are variadic lambdas needed (apart from they should just work)? At present,
-betterC tries to do codegen for functions that are only intended for CTFE,
unjustifiably precluding CTFE for anything that requires GC, typeinfo etc. The
only existing workaround is to transform the functions into lamdas. However,
writing functions such as string formatters is painful without variadic
parameters. It would become bearable, if this bug is fixed, until a proper way
of marking CTFE-only functions is implemented.

--
Oct 16 2019