In the context of building a compiler AST I have structs that are very similar, representing different constructs:
struct Identifier(CommonTrait):
var text: String
struct Expression(CommonTrait):
var text: String
var expr: Expression
I then define a Variant across all these various structs:
comptime ASTNode = Variant[
Identifier,
Expression,
...
]
Since Mojo can verify that all members share ‘text’ in the exact same location, would it be possible to allow:
var myNode: ASTNode
...
print(myNode.text)
or similarly, given that all members share a common trait:
myNode.common_trait_method()