is(T : A!T) tells if T can automatically be converted to A!T. The
last line below is doing just that, yet the template constraint does not work.
class A(T) if (is(T : A!T))
{
}
// if (is(T : A!T)) gives this error:
// Error: template instance x.A!(B) does not match
// template declaration A(T) if (is(T : A!T))
// while looking for match for A!(B)
class B : A!(B)
{
}
void main(string[] args)
{
B b = new B();
A!B a = b; // compiles fine
}
Comment #1 by k.hara.pg — 2016-05-13T21:27:39Z
This is expected behavior. While testing a template constraint, the template is not yet instantiated.
When A!B is started to instantiation, its template constraint is(B : A!B) will be tested. BUT the instance A!B is not yet instantiated, so compiler cannot know it will be a class.