On Sunday, 26 February 2023 at 02:33:21 UTC, guacs wrote:
NOTE: The error is happening when I'm using the SumType and I
suspect that I'm using it incorrectly.
I am not sure whether this is the specific error that is causing
your problem, but there is a mistake in your use of `SumType` in
`expr.d`. [1]
On line 10, you declare
alias Expression = SumType!(Number, Binary, Unary, Group);
Later, you declare `Binary` and `Unary` like this:
struct Binary {
Expression leftOperand;
Expression rightOperand;
Token operator;
// etc.
}
struct Unary {
Expression operand;
Token operator;
// etc.
}
Since `Expression` contains `Binary` and `Unary`, and `Binary`
and `Unary` contain `Expression`, that means `Expression`
contains itself--which is not allowed, because it would result in
`Expression.sizeof` being infinite.
The fix is to change `Binary` and `Unary` so that they contain
*pointers* to `Expression`, like this:
struct Binary {
Expression* leftOperand; // pointer
Expression* rightOperand; // pointer
Token operator;
// etc.
}
struct Unary {
Expression* operand; // pointer
Token operator;
// etc.
}
[1] https://github.com/VisakhChekur/meval/blob/error/source/expr.d