#tagged union that depends on itself

1 messages · Page 1 of 1 (latest)

ivory sequoia
#

writing a top down parser for a programming language as a project,

pub const Expr = union(ExprKind) {
    e_literal: BCValue,
    e_negation: Expr,
    e_not: Expr,
    e_grouping: Expr,
    e_ident: []const u8, // owned slice
    e_typecast: Typecast,
    e_array_literal: []Expr,
    e_binary: BinaryExpr,
    e_array_index: ArrayIndex,
};

The compiler screams at me for doing this, any fixes? is prefixing these enum members with e_ frowned upon as well?

unique pawn
#

What's the error reported by the compiler?

ivory sequoia
#
src/ast_types.zig:69:18: error: union 'ast_types.Expr' depends on itself
pub const Expr = union(ExprKind) {
                 ^~~~~

sorry for being unclear

ivory sequoia
#

ive been reading up and it looks like the size must be known at compile time (fair) but even when i add indirection it doesnt actually work

#
pub const Expr = union(ExprKind) {
    e_literal: BCValue,
    e_negation: *const Expr, // owned ptr
    e_not: *const Expr, // owned ptr
    e_grouping: *const Expr, // owned ptr
    e_ident: []const u8, // owned slice
    e_typecast: Typecast,
    e_array_literal: []const Expr,
    e_binary: BinaryExpr,
    e_array_index: ArrayIndex,
};

produces the same error