Please file a bug. This should be a compiler error instead of a crash.
The reason you can’t do this is because the type has infinite size. Unlike in Python, Optional[Employee] is a single allocation, which contains an Optional[Employee], and so on.
This would work for you:
from memory import OwnedPointer
fn main():
_e = Employee("me", None)
@value
struct Employee:
var name: String
var assistant: Optional[OwnedPointer[Employee]]
But right now we’re reworking parts of the standard library so there’s an interface conflict.
That did not work. Below are the errors that I get:
error: cannot bind type 'OwnedPointer[Employee]' to trait 'Copyable & Movable'
var assistant: Optional[OwnedPointer[Employee]]
~~~~~~~~~~~~^~~~~~~~~~
note: struct 'OwnedPointer[T]' does not implement all requirements for 'Copyable'
note: required function '__copyinit__' is not implemented
But right now we’re reworking parts of the standard library so there’s an interface conflict.
What I was trying to say with this is that there isn’t a good way to do this at the moment in safe Mojo. We’re in the middle of applying some recent advancements to the type system.