Comment #0 by bearophile_hugs — 2010-06-06T06:53:06Z
This is wrong D2 program:
void main() {
template Foo {}
}
DMD v2.046 prints at compile-time:
test.d(2): found 'template' instead of statement
test.d(3): unrecognized declaration
But a better and more readable error message can be:
test.d(2): Error: template definitions aren't allowed inside functions.
Comment #1 by bearophile_hugs — 2010-06-06T07:24:00Z
A similar error message can be used for imports too inside functions.
Comment #2 by ellery-newcomer — 2010-06-06T08:22:55Z
Created attachment 657
error messages!
good ideas.
note this patch also enables import expressions at statement level, which wasn't previously allowed. it yields a better error message this way (I think).
Comment #3 by bearophile_hugs — 2010-06-06T08:38:02Z
Comment #5 by bearophile_hugs — 2012-10-27T04:49:59Z
Templated functions are allowed inside functions:
void main() {
T foo(T)(T x) {
return x * x;
}
assert(foo(10) == 100);
assert(foo(10L) == 100L);
}
So why are templates not accepted inside functions? It's a handy "all the turtles down" as Walter says.
Comment #6 by yebblies — 2012-10-27T04:54:06Z
(In reply to comment #5)
> Templated functions are allowed inside functions:
>
> So why are templates not accepted inside functions? It's a handy "all the
> turtles down" as Walter says.
That would be "turtles all the way down".
I agree, but this bug report is about the poor error message.
Comment #7 by bearophile_hugs — 2012-10-27T06:13:57Z
(In reply to comment #6)
> I agree, but this bug report is about the poor error message.
Sure.
Closed.
Comment #8 by yebblies — 2012-10-27T06:15:06Z
This bug still exists for D1.
Comment #9 by pro.mathias.lang — 2020-08-06T14:26:33Z
D1 is gone, it works in D2 (you can even declare templates, not only functions), so closing.