Bug 18646 – [REG 2.079.0] Recursive template expansion incorrectly reported

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-03-22T07:07:29Z
Last change time
2023-01-01T06:25:01Z
Keywords
pull, rejects-valid
Assigned to
No Owner
Creator
Ontonator

Comments

Comment #0 by publicnator — 2018-03-22T07:07:29Z
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 {}
Comment #1 by publicnator — 2018-03-22T07:10:19Z
It also should be noted that the aliases don't have to be aliases. Any reference to the class works (e.g. variable with type, method with parameter or return type, etc.).
Comment #2 by ibuclaw — 2022-12-27T18:01:45Z
*** Issue 19585 has been marked as a duplicate of this issue. ***
Comment #3 by ibuclaw — 2022-12-27T18:02:41Z
*** Issue 22813 has been marked as a duplicate of this issue. ***
Comment #4 by ibuclaw — 2022-12-27T18:03:55Z
Extra testcase: --- struct A { M2 stdin; } mixin template Handle(T, T invalid_value = T.init) {} struct M1 { mixin Handle!(size_t); } struct M2 { mixin Handle!(M1); }
Comment #5 by ibuclaw — 2022-12-27T18:04:10Z
Extra testcase --- struct Template(int i) { } uint f() { Template!(1) x; return 0; } immutable constant = f(); alias X = Template!constant;
Comment #6 by ibuclaw — 2022-12-27T18:05:48Z
Comment #7 by dlang-bot — 2022-12-27T23:08:00Z
@ibuclaw created dlang/dmd pull request #14745 "fix Issue 18646 - [REG 2.079.0] Recursive template expansion incorrectly reported" fixing this issue: - fix Issue 18646 - [REG 2.079.0] Recursive template expansion incorrectly reported https://github.com/dlang/dmd/pull/14745
Comment #8 by dlang-bot — 2022-12-28T12:46:29Z
dlang/dmd pull request #14745 "fix Issue 18646 - [REG 2.079.0] Recursive template expansion incorrectly reported" was merged into stable: - 291b60e93ed60e76c8501398b3126ef423c68291 by Iain Buclaw: fix Issue 18646 - [REG 2.079.0] Recursive template expansion incorrectly reported https://github.com/dlang/dmd/pull/14745
Comment #9 by dlang-bot — 2023-01-01T06:25:01Z
dlang/dmd pull request #14765 "merge stable" was merged into master: - 302ff4bb109f3bc2011490f696c125ecb781e879 by Iain Buclaw: fix Issue 18646 - [REG 2.079.0] Recursive template expansion incorrectly reported https://github.com/dlang/dmd/pull/14765