[Issue 16481] invalid code accepted leading to linker error
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Fri Sep 9 07:03:40 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=16481
--- Comment #1 from John Colvin <john.loughran.colvin at gmail.com> ---
Reduced version without phobos imports:
void blah()
{
int[] a;
a.map!(x => x.map!to);
}
template to()
{
}
template map(fun...)
{
auto map(Range)(Range r)
{
alias RE = Range;
alias _fun = unaryFun!fun;
assert(!is(typeof(_fun(RE.init))));
MapResult!(_fun, Range)(r);
}
}
struct MapResult(alias fun, Range)
{
alias R = Range;
R _input;
this(R)
{
}
@property front()
{
fun(_input);
}
}
template unaryFun(alias fun)
{
alias unaryFun = fun;
}
Undefined symbols for architecture x86_64:
"_D3mod26__T9MapResultS73mod2toTAiZ9MapResult6__ctorMFNaNbNcNiNfAiZS3mod26__T9MapResultS73mod2toTAiZ9MapResult",
referenced from:
_D3mod17__T3mapS73mod2toZ11__T3mapTAiZ3mapFNaNbNiNfAiZv in mod.o
If you comment out the assert then you get this error instead:
mod.d(34): Error: template mod.to cannot deduce function from argument types
!()(int[]), candidates are:
mod.d(8): mod.to()
mod.d(19): Error: template instance mod.MapResult!(to, int[]) error
instantiating
mod.d(5): instantiated from here: map!(int[])
mod.d(34): instantiated from here: __lambda1!(int[])
mod.d(19): instantiated from here: MapResult!(__lambda1, int[])
mod.d(5): instantiated from here: map!(int[])
which is what I expect and looks ok.
--
More information about the Digitalmars-d-bugs
mailing list