Issue 18037 - Lambda with specified template type parameter does not work with IFTI
Summary: Lambda with specified template type parameter does not work with IFTI
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-12-06 10:40 UTC by Ali Ak
Modified: 2024-11-11 04:39 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 Ali Ak 2017-12-06 10:40:16 UTC
When you declare a template lambda:

immutable lambda(T) = (T n) => n * n;

and call it without an explicit type it errors with with:

lambda cannot deduce function from argument types !()(int)

auto x = lambda!int(2); // works
auto x = lambda(2); // not works

Is this a bug? - tired on dmd v2.077.1
Comment 1 Steven Schveighoffer 2017-12-06 15:43:47 UTC
Tested back to 2.070.0, which is where short lambda syntax was introduced. Still fails.

The immutable looks odd, but even with alias this doesn't work.

alias lambda(T) = (T n) => n * n;

should expand to:

template lambda(T)
{
    alias lambda = (T n) => n * n;
}

Neither of these successfully use IFTI.

However, these all work:

alias lambda = (int n) => n * n;
alias lambda = n => n * n;