template A(T)
{
alias T type;
}
template B(T:A!(T).type) // I think compiler should ban the use of reuse the same type identifier in the specialization part.
{
}
//mixin B!(int); // even though you can't instantiate the template, the compiler can actually emit nicer message;
Comment #1 by smjg — 2007-10-29T07:52:38Z
AIUI this is by design, though admittedly it's a rather strange design.
http://www.digitalmars.com/d/1.0/template.html
template TBar(T : T*) { }
alias TBar!(char*) Foo3; // (2) T is deduced to be char
Basically, what it means is that if a template parameter name is re-used as part of the specialization, it has the meaning of 'anything', and within the template, the identifier denotes what it represented within the specialization.
But where T is used as a template parameter in the specialization, I'm not sure it can work in the general case. After all, there's a potential infinitude of templates to instantiate to try to find a match. So I'm still not sure that the compiler should accept the template declaration.
Comment #2 by razvan.nitu1305 — 2019-08-21T11:03:40Z
The template is not semantically analyzed before instantiation, it is only parsed, so the compiler cannot reject the template definition before actually instantiating it. This is clearly stated in the spec. The error message points this out: "mixin test.B!(A!int) does not match template declaration B(T : A!T)".
Closing as WONTFIX.