Bug 18850 – Template overload incorrectly results in recursive expansion error

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-05-10T18:04:34Z
Last change time
2018-05-14T15:52:00Z
Assigned to
No Owner
Creator
Jonathan Marler

Comments

Comment #0 by johnnymarler — 2018-05-10T18:04:34Z
bug.d ---------------------------- struct Foo(T) { alias Foo = Foo!(T, T.init); } struct Foo(T, T initialValue) { private T value = initialValue; } Foo!int n; ---------------------------- > dmd -c file.d bug.d(3): Error: template instance `Foo!(T, T.init)` recursive template expansion bug.d(9): Error: template instance `bug.Foo!int` error instantiating
Comment #1 by ag0aep6g — 2018-05-10T20:15:42Z
(In reply to Jonathan Marler from comment #0) > alias Foo = Foo!(T, T.init); Just that line alone shows the same behavior. And that might make it more obvious what's happening: In the struct body, "Foo" refers to the alias, not the templates. You can refer to the templates with `.Foo`: ---- struct Foo(T) { alias Foo = .Foo!(T, T.init); } struct Foo(T, T initialValue) { private T value = initialValue; } Foo!int n; ----
Comment #2 by johnnymarler — 2018-05-14T15:52:00Z
Yes I made a mistake here. Had a temporary brain lapse. I mean to define Foo as a template, not a templated struct.