digitalmars.D - Unwanted recursive expansion
- Luc J. Bourhis (32/32) Jan 15 2015 Consider the following program:
- Daniel =?UTF-8?B?S296w6Fr?= via Digitalmars-d (27/69) Jan 15 2015 V Thu, 15 Jan 2015 12:31:00 +0000
- Luc J. Bourhis (4/7) Jan 15 2015 Thanks for this fix. But could you explain to me why there is a
Consider the following program: struct Expr(E) { const E expr; // If I replace the return type with "auto", dmd enters into an infinite loop instead of failing (see below) property Expr!(Transposed!E) trans() { alias R = Transposed!E; return Expr!R(R(expr)); } } struct Transposed(E) { const E expr; } struct Matrix { property auto asExpression() { return Expr!(Matrix)(this); } alias asExpression this; } void main() { auto a = Matrix(); auto e = a.trans; pragma(msg, typeof(e).stringof); } It fails to compile: ~> dmd -v | head -n1 DMD64 D Compiler v2.066-devel ~> dmd -c expression_template.d expression_template.d(4): Error: template instance expression_template.Transposed!(Transposed!(Transposed!(Transposed!( .................. ) recursive expansion Am I missing something?
Jan 15 2015
V Thu, 15 Jan 2015 12:31:00 +0000 "Luc J. Bourhis via Digitalmars-d" <digitalmars-d puremagic.com> napsáno:Consider the following program: struct Expr(E) { const E expr; // If I replace the return type with "auto", dmd enters into an infinite loop instead of failing (see below) property Expr!(Transposed!E) trans() { alias R = Transposed!E; return Expr!R(R(expr)); } } struct Transposed(E) { const E expr; } struct Matrix { property auto asExpression() { return Expr!(Matrix)(this); } alias asExpression this; } void main() { auto a = Matrix(); auto e = a.trans; pragma(msg, typeof(e).stringof); } It fails to compile: ~> dmd -v | head -n1 DMD64 D Compiler v2.066-devel ~> dmd -c expression_template.d expression_template.d(4): Error: template instance expression_template.Transposed!(Transposed!(Transposed!(Transposed!( .................. ) recursive expansion Am I missing something?This is ok, there is really recursive expansion here, I guess you want something like this? struct Expr(E) { const E expr; property auto trans() { alias R = Transposed!E; return R(expr); } } struct Transposed(E) { const E expr; } struct Matrix { property auto asExpression() { return Expr!(Matrix)(this); } alias asExpression this; } void main() { auto a = Matrix(); auto e = a.trans; pragma(msg, typeof(e).stringof); }
Jan 15 2015
On Thursday, 15 January 2015 at 13:14:41 UTC, Daniel Kozák via Digitalmars-d wrote:This is ok, there is really recursive expansion here, I guess you want something like this? [...]Thanks for this fix. But could you explain to me why there is a recursive expansion?
Jan 15 2015