Help needed for "recursive template expansion error"

Nicholas Wilson iamthewilsonator at
Mon Oct 21 18:45:44 UTC 2019

On Monday, 21 October 2019 at 18:14:11 UTC, Anthony Abeo wrote:
> Hello all,
> I have an Algebraic type of structs as shown below. One of the 
> structs is the `Code` struct and this struct holds an array of 
> ATTR_INFO. It is self-referential. Obviously the compiler is 
> unable to get the maximum size of ATTR_INFO at compile-time, 
> hence throwing the error. I will be very grateful for any help 
> to resolve this issue.
> alias ATTR_INFO = Algebraic!(SourceFile, ConstantValue, 
> Excepsion, Code,
> LineNumberTable, LocalVariableTable);
> struct Code
> {
> 	size_t attribute_name_index;
> 	size_t attribute_len;
> 	size_t max_stack;
> 	size_t max_locals;
> 	size_t code_length;
> 	const(ubyte[]) code;
> 	size_t exception_table_length;
> 	Tuple!(size_t, size_t, size_t, size_t) exception_table;
> 	size_t attribute_count;
> 	ATTR_INFO[] attributes;
> }

Please post such questions to the learn forum in the future.

One way to fix this is to use the `This` type to perform type 
substitution in the Algebraic which refers to the final type of 
the Algebraic, used like `alias F = Algebraic!(int, string, 
This[])`.  Where F is either an int, a string or an array of Fs.

You could probably remove `attributes` from code and use

alias ATTR_INFO = Algebraic!(SourceFile, ConstantValue,  
Excepsion, Tuple!(Code,This[]), LineNumberTable, 

More information about the Digitalmars-d mailing list