Skip to content

zig: tagged-union variants are dropped from the graph #4049

Description

@rajatnagda45

What happens

A Zig tagged union keeps its methods but loses every variant. Given:

const Shape = union(enum) {
    circle: f64,
    rectangle: struct { w: f64, h: f64 },
    point,

    pub fn area(self: Shape) f64 { return 0; }
};

the graph has Shape and .area() but no circle / rectangle / point, so the union sits as a near-memberless leaf.

Why

The container_field branch in graphify/extractors/zig.py only fires when the field's parent is an enum_declaration. A tagged union's variants are container_field nodes under a union_declaration, so they fall through and are never emitted.

Expected

A tagged union's variants are its discriminant cases — the same shape as enum members — so each should become a node with a case_of edge to the union, matching enums (Java #1719, Swift, Scala) and the Zig enum / error-set handling already in place. A bare union { ... } has typed data fields (not cases) and should stay untouched, like a struct's fields.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions