You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recursive enum cases currently cause both the IDE and beefbuild to crash, which, in addition to making it impossible to implement something like an arithmetic expression tree, makes it difficult to implement any other kind of tree structure which might refer to itself in some way, such as a JSON value (at least in the IDE's case)
This crashes both the IDE and the compiler without fail:
enum Expression
{
case Number( double x );
case Add( Expression left, Expression right );
// other arithmetic operations
}
And this will crash just the IDE when typed out normally:
enum JsonValue
{
case Null;
case Array( JsonValue[] items );
}
The IDE crashes just after inserting JsonValue when declaring the Array case before even being able to insert the square brackets, requiring some other external editor, but otherwise it works as expected once that's sorted out.
I'm assuming naked recursion (such as in example 1) without putting the Self behind a pointer, array, or some other form of indirection is intended since doing the same thing with a struct correctly produces an error without crashing.
As an aside, what is the idiomatic way of writing the first snippet properly? Pointer? Some kind of Box<T> like Rust?
The text was updated successfully, but these errors were encountered:
Yes that is indeed illegal... thanks for finding that, I'll make it be a pretty error message. If you didn't want to use OOP, then the idiomatic way would be to make 'left' and 'right' pointers to Expression.
You can decide how you want to allocate and deallocate the memory for those expressions, but for an AST you probably just want to use a BumpAllocator instance which is pretty much the fastest possible allocation, and no need for deleting the individual Expression instances since the memory will all be recovered when the single BumpAllocator instance is destroyed - and since the enum won't require any per-instance destructors. You'll find that this technique is quite a lot faster than a Rust enum with Box values.
Recursive enum cases currently cause both the IDE and
beefbuild
to crash, which, in addition to making it impossible to implement something like an arithmetic expression tree, makes it difficult to implement any other kind of tree structure which might refer to itself in some way, such as a JSON value (at least in the IDE's case)This crashes both the IDE and the compiler without fail:
And this will crash just the IDE when typed out normally:
The IDE crashes just after inserting
JsonValue
when declaring theArray
case before even being able to insert the square brackets, requiring some other external editor, but otherwise it works as expected once that's sorted out.I'm assuming naked recursion (such as in example 1) without putting the
Self
behind a pointer, array, or some other form of indirection is intended since doing the same thing with a struct correctly produces an error without crashing.As an aside, what is the idiomatic way of writing the first snippet properly? Pointer? Some kind of
Box<T>
like Rust?The text was updated successfully, but these errors were encountered: