Help needed for "recursive template expansion error"
Simen Kjærås
simen.kjaras at gmail.com
Tue Oct 22 08:42:48 UTC 2019
On Tuesday, 22 October 2019 at 08:16:47 UTC, Anthony Abeo wrote:
> On Monday, 21 October 2019 at 18:45:44 UTC, Nicholas Wilson
> wrote:
>> On Monday, 21 October 2019 at 18:14:11 UTC, Anthony Abeo wrote:
>>> [...]
>>
>> 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,
>> LocalVariableTable);
>
> - Please post such questions to the learn forum in the future.
> Noted. I will do that next time.
>
> I tried your suggestion and it fails silently; no error message
> / stack trace.
I'd suggest using SumType
(https://code.dlang.org/packages/sumtype) instead of std.variant,
as the latter has its share of problems.
Otherwise, this kinda works, but can hardly be called anything
but a horrible hack:
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;
private ubyte[] _attributes;
}
ref ATTR_INFO[] attributes(return ref Code code)
{
return *cast(ATTR_INFO[]*)&code._attributes;
}
It will need some fixing if you have any destructors, as Code
treats those ATTR_INFOs as just a bunch of bytes, but it will
make the code compile and it might be good enough. Seriously
though, check out SumType instead.
--
Simen
More information about the Digitalmars-d
mailing list