Bug 8632 – DMD accepts illegal template metaprogram

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-09-08T15:01:00Z
Last change time
2013-11-24T10:31:11Z
Keywords
accepts-invalid
Assigned to
nobody
Creator
timon.gehr

Comments

Comment #0 by timon.gehr — 2012-09-08T15:01:25Z
DMD 2.060: template BrokenY(alias F){ template BrokenY(A...){ template Z(alias X){ alias F!(X,A) Z; } alias Z!Z BrokenY; } } template AlmostFact(alias BrokenFact, int n){ static if(n) enum AlmostFact = n*BrokenFact!(n-1); else enum AlmostFact=1; } alias BrokenY!AlmostFact BrokenFact; pragma(msg, BrokenFact!3); // "36" DMD accepts this code, but it is invalid. It seems to be some kind of lookup problem. Consistently renaming one of the two BrokenFact aliases makes the problem disappear.
Comment #1 by yebblies — 2013-11-24T08:08:39Z
Errors, errors everywhere. DMD v2.065 DEBUG testx.d(6): Error: alias testx.BrokenY!(AlmostFact).BrokenFact!3.BrokenY recursive alias declaration testx.d(10): Error: template instance BrokenFact!(n - 1) BrokenFact is not a template declaration, it is a variable testx.d(4): Error: template instance testx.F!(2, 3) error instantiating testx.d(10): instantiated from here: BrokenFact!2 testx.d(4): instantiated from here: F!(Z, 3) testx.d(6): instantiated from here: Z!(Z) testx.d(14): instantiated from here: BrokenFact!3 testx.d(10): Error: template instance testx.BrokenY!(AlmostFact).BrokenFact!3.BrokenFact!2 error instantiating testx.d(4): instantiated from here: F!(Z, 3) testx.d(6): instantiated from here: Z!(Z) testx.d(14): instantiated from here: BrokenFact!3 testx.d(4): Error: template instance testx.F!(Z, 3) error instantiating testx.d(6): instantiated from here: Z!(Z) testx.d(14): instantiated from here: BrokenFact!3 testx.d(6): Error: template instance testx.BrokenY!(AlmostFact).BrokenFact!3.Z!(Z) error instantiating testx.d(14): instantiated from here: BrokenFact!3 testx.d(14): Error: template instance testx.BrokenY!(AlmostFact).BrokenFact!3 error instantiating testx.d(14): while evaluating pragma(msg, BrokenFact!3) No idea what that code is supposed to do, but maybe it's fixed?
Comment #2 by timon.gehr — 2013-11-24T10:31:11Z
(In reply to comment #1) > Errors, errors everywhere. > > DMD v2.065 DEBUG > testx.d(6): Error: alias testx.BrokenY!(AlmostFact).BrokenFact!3.BrokenY > recursive alias declaration I am not sure why this error should occur. Maybe this is spurious. > testx.d(10): Error: template instance BrokenFact!(n - 1) BrokenFact is not a > This is indeed the exact problem. > No idea what that code is supposed to do, It is supposed to make the compiler emit errors. :o) It is a more or less random variation of the following valid code, also from my test suite (this implements a template-level fixpoint combinator without using explicit recursive template instantiations): template Y(alias F){ template Z(alias X){ template Z(A...){ alias F!(X!X,A) Z; } } alias Z!Z Y; } template AlmostFact(alias Fact, int n){ static if(n) enum AlmostFact = n*Fact!(n-1); else enum AlmostFact=1; } alias Y!AlmostFact Fact; pragma(msg, "Fact: ",Fact!5); static assert(Fact!5==120); > but maybe it's fixed? Definitely. Thanks for checking!