[Issue 18646] New: Recursive template expansion incorrectly reported for certain templated classes

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 22 07:07:29 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=18646

          Issue ID: 18646
           Summary: Recursive template expansion incorrectly reported for
                    certain templated classes
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: publicnator at gmail.com

With certain configurations of templated classes/interfaces with refinements, a
recursive template expansion is incorrectly reported. This only occurs if the
classes are in a certain order.

To reproduce:

    1) Create a D file and enter the following code:

        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 {}

    2) Compile the code.

Actual result:
    test.d(12): Error: class `test.TemplatedClass(T : SuperClass)` recursive
template expansion
    test.d(12):        while looking for match for TemplatedClass!(C)

Expected result: no error

Build 2018-03-22 on Mac OS 10.12.6 on DMD64 D Compiler v2.079.0

On the other hand, the following two examples both work:

1) Changed specialisation to constraint:

    void main() {}

    class SuperClass {}

    class TemplatedClass(T)
    if (is(T : SuperClass)) {}

    class A : SuperClass {
        alias T = TemplatedClass!B;
    }

    class B : SuperClass {
        alias T = TemplatedClass!C;
    }

    class C : SuperClass {}

2) Reordered:

    void main() {}

    class SuperClass {}

    class TemplatedClass(T : SuperClass) {}

    class B : SuperClass {
        alias T = TemplatedClass!C;
    }

    class A : SuperClass {
        alias T = TemplatedClass!B;
    }

    class C : SuperClass {}

--


More information about the Digitalmars-d-bugs mailing list