recursive template expansion: Why does this not compile?

ag0aep6g anonymous at example.com
Wed Mar 21 06:39:22 UTC 2018


On 03/21/2018 01:47 AM, Ontonator wrote:
> The following code does not compile:
>> void main() {}
>>
>> class SuperClass {}
>>
>> class TemplatedClass(T : SuperClass) {}
>>
>> class A : SuperClass {
>>     alias T = TemplatedClass!B;
>> }
>>
>> class B : SuperClass {
>>     alias T = TemplatedClass!C;
>> }
>>
>> class C : SuperClass {}
> 
> It gives the error:
>> test.d(12): Error: class `test.TemplatedClass(T : SuperClass)` 
>> recursive template expansion
>> test.d(12):        while looking for match for TemplatedClass!(C)
> 
> The aliases do not have to be aliases, as long as there is some 
> reference to the class (e.g. method and variable declarations also 
> work). What exactly is the reason for this error?

Compiler bug. It works when you move the declaration of `B` before the 
one of `A`. Order shouldn't matter there.


More information about the Digitalmars-d-learn mailing list