Bug 8994 – typeof fails when passing delegate as alias parameter
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-11-10T10:19:00Z
Last change time
2013-11-21T23:16:22Z
Assigned to
nobody
Creator
deadalnix
Comments
Comment #0 by deadalnix — 2012-11-10T10:19:48Z
See code below :
class A {
void foo() {
new B!(a => visit(a), A)();
}
A visit(A a) {
return a;
}
}
class B(alias fun, T) {
T t;
typeof(fun(t)) result;
}
dmd output typeoffail.d(3): Error: need 'this' to access member visit
However, if typeof(fun(t)) result; is replaced by T result; or A result; everything work as expected.
Comment #1 by maxim — 2012-11-10T11:54:49Z
This is issue 8899. Change lambda template a => visit(a) to lambda function (A a) => visit(a) and the code compiles.
Comment #2 by deadalnix — 2012-11-11T10:29:36Z
(In reply to comment #1)
> This is issue 8899. Change lambda template a => visit(a) to lambda function (A
> a) => visit(a) and the code compiles.
I'm not sure at the problem trigger itself precisely when using typeof.
Comment #3 by maxim — 2012-11-11T18:25:37Z
(In reply to comment #2)
> (In reply to comment #1)
> > This is issue 8899. Change lambda template a => visit(a) to lambda function (A
> > a) => visit(a) and the code compiles.
>
> I'm not sure at the problem trigger itself precisely when using typeof.
I think that using lambda without parameter type is often a problem. In lucky cases there is compilation error and in worse cases this leads to mysterious bugs.
Comment #4 by k.hara.pg — 2013-11-21T23:16:22Z
Fixed in 2.064.
*** This issue has been marked as a duplicate of issue 11220 ***