Bug 16021 – Template constraint bug

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-05-12T16:11:00Z
Last change time
2016-05-13T21:27:39Z
Assigned to
nobody
Creator
eric

Comments

Comment #0 by eric — 2016-05-12T16:11:35Z
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.