D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 16345 - IFTI fails with lazy variadic function in some cases
Summary: IFTI fails with lazy variadic function in some cases
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P3 minor
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2016-08-01 09:12 UTC by Mario Kroeplin
Modified: 2024-12-13 18:49 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Mario Kroeplin 2016-08-01 09:12:44 UTC
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(...)`.
Comment 1 ag0aep6g 2016-08-01 10:55:01 UTC
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) */
----
Comment 2 dlangBugzillaToGithub 2024-12-13 18:49:21 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/19167

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB