[Issue 11012] [TDPL] is(typeof(f) == function) fails with some functions
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Fri Jun 23 07:14:04 PDT 2017
https://issues.dlang.org/show_bug.cgi?id=11012
ZombineDev <petar.p.kirov at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |petar.p.kirov at gmail.com
--- Comment #5 from ZombineDev <petar.p.kirov at gmail.com> ---
(In reply to Alexander from comment #3)
> static assert(is(typeof( (){} ) == function)); // fails as well
>
> This issue doesn't allow to get lambda parameter types tuple, and this
> blocks my development. I'll try to have a look at the dmd source.
Is the blocking issue that in code similar to the following, there's an error
on line 11:
---
import std.traits;
pragma (msg, ReturnType!( (){} )); // void
pragma (msg, Parameters!( (){} )); // ()
pragma (msg, ReturnType!( (int x, double y) => "test" )); // string
pragma (msg, Parameters!( (int x, double y) => "test" )); // (int, double)
void lambdaTypeWithParameter(alias lambda, Param)(Param p)
{
pragma (msg, Parameters!(lambda)); // line 11 - doesn't compile
alias RT = typeof(lambda(p));
pragma (msg, RT); // line 15
}
void main()
{
lambdaTypeWithParameter!(x => "test2")(true); // line 15 -> string
lambdaTypeWithParameter!(x => x)(2); // line 15 -> int
lambdaTypeWithParameter!(x => 3.0 * x)(2); // line 15 -> double
}
---
?
If that's the case, the error is expected since the lambda in that context is
polymorphic - an un-instantiated function template meaning that its parameters
are not bound to a specific type.
--
More information about the Digitalmars-d-bugs
mailing list