Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IFTI fails with lazy variadic function in some cases #19167

Open
dlangBugzillaToGithub opened this issue Aug 1, 2016 · 1 comment
Open

IFTI fails with lazy variadic function in some cases #19167

dlangBugzillaToGithub opened this issue Aug 1, 2016 · 1 comment
Labels

Comments

@dlangBugzillaToGithub
Copy link

Mario Kroeplin reported this on 2016-08-01T09:12:44Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=16345

CC List

  • ag0aep6g

Description

The following code does not compile:

void all(string file = __FILE__, size_t line = __LINE__)(void delegate()[] dgs ...)
{
    foreach (dg; dgs)
    {
        dg();
    }
}

void main()
{
    all(
        assert(true),
    );
}

Error: template all cannot deduce function from argument types !()(void), candidates are:
       all(string file = __FILE__, ulong line = __LINE__)(void delegate()[] dgs...)

Workaround: call `all!()(...)` instead of `all(...)`.
@dlangBugzillaToGithub
Copy link
Author

ag0aep6g commented on 2016-08-01T10:55:01Z

For reference, the spec describes lazy variadic functions here:
http://dlang.org/spec/function.html#lazy_variadic_functions

The test case doesn't need the template parameters to fail. This fails, too:

----
void all()(void delegate()[] dgs ...) {}
void f() {}
void main() { all(f()); } /* Error: template test.all cannot deduce function from argument types !()(void) */
----

It works when the return type is int or another primitive type, including pointers and arrays:

----
void all()(int delegate()[] dgs ...) {}
int f() { return 0; }
void main() { all(f()); } /* no error */
----

But it fails with Object and user-defined aggregates. Most peculiarly, it also fails with an alias to a primitive type:

----
alias T = int;
void all()(T delegate()[] dgs ...) {}
T f() { return T.init; }
void main() { all(f()); } /* Error: template test.all cannot deduce function from argument types !()(int) */
----

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant