digitalmars.D.bugs - [Issue 9555] New: Type deduction for new lambda syntax literals breaks with templates
- d-bugmail puremagic.com (35/35) Feb 21 2013 http://d.puremagic.com/issues/show_bug.cgi?id=9555
- d-bugmail puremagic.com (31/31) Feb 21 2013 http://d.puremagic.com/issues/show_bug.cgi?id=9555
- d-bugmail puremagic.com (12/12) Feb 21 2013 http://d.puremagic.com/issues/show_bug.cgi?id=9555
- d-bugmail puremagic.com (6/6) Feb 21 2013 http://d.puremagic.com/issues/show_bug.cgi?id=9555
- d-bugmail puremagic.com (8/8) Feb 21 2013 http://d.puremagic.com/issues/show_bug.cgi?id=9555
- d-bugmail puremagic.com (24/27) Feb 21 2013 http://d.puremagic.com/issues/show_bug.cgi?id=9555
- d-bugmail puremagic.com (9/9) Feb 21 2013 http://d.puremagic.com/issues/show_bug.cgi?id=9555
http://d.puremagic.com/issues/show_bug.cgi?id=9555
Summary: Type deduction for new lambda syntax literals breaks
with templates
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody puremagic.com
ReportedBy: m.strashun gmail.com
Simple motivating example:
--- test.d ---
import std.functional;
void main()
{
auto deleg = toDelegate(a => a > 2);
}
------
--- shell ---
$ rdmd test.d
test.d(5): Error: template std.functional.toDelegate does not match any
function template declaration. Candidates are:
/usr/include/dmd/phobos/std/functional.d(722):
std.functional.toDelegate(F)(auto ref F fp) if (isCallable!(F))
test.d(5): Error: template std.functional.toDelegate(F)(auto ref F fp) if
(isCallable!(F)) cannot deduce template function from argument types !()(void)
------
Type of lambda was deduced as "void" here.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 21 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9555
Maxim Fomin <maxim maxim-fomin.ru> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |maxim maxim-fomin.ru
Resolution| |INVALID
---
Actually type of lambda was not deduced to void, void here is pseudo type of
non-instantiated template, because a => a > 2 is a lambda template. If you
append type of a parameter, this would work, for ex:
import std.functional;
void main()
{
auto deleg = toDelegate( (int a) => a > 2);
}
Since there is no guesses what type of "a" can be in the original code,
template cannot be instantiated.
By the way, idea mentioned in forum discussion that there is problem with new
(lambda) syntax is also wrong, because the code can be rewritten with delegate
template:
import std.functional;
void main()
{
auto deleg = toDelegate( delegate (a) { return a > 2; } );
}
with the same problem and same error message.
Close this as invalid.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 21 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9555
bioinfornatics <bioinfornatics gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bioinfornatics gmail.com
04:39:49 PST ---
but if your delegate look like : in bool delegate(in size_t) lambda
you can't use (in int a) => a > 2)
or (const int a) => a > 2)
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 21 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9555 04:41:32 PST --- skip my comment that is allowed to do ((in int a) => a > 2) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 21 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9555 Waa, it is a template? Unexpected. What about turning this into enhancement request to improve error message though? Something like "not enough context to deduce lambda type". -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 21 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9555 ---Waa, it is a template? Unexpected. What about turning this into enhancement request to improve error message though? Something like "not enough context to deduce lambda type".Enough context can be provided later. template get(alias a) { alias a!int get; } template foo(fun...) { alias get!fun foo; } void main() { alias foo!(a=>a) a; assert(a(1) == 1); assert(a(1.0) is 1.0); //NG } Note, this is reduced from how map and unaryfun works. If you turn it into context-independent error, this would mean code break for some usages which are currently accepted. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 21 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9555 I was speaking exactly about the case when it is used and context is lacking. This message "cannot deduce template function from argument types !()(void)" is very misleading for someone who is not aware of lambda implementation inner details. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 21 2013









d-bugmail puremagic.com 