Skip to content

[render] union type decl renders as <unknown type decl> (no Union branch) #1023

Closed

Description

@eas4ai

AUDIT finding (read-only review at 450733e, verified against source).

render.w has no Union branch: a union type decl falls through to
<unknown type decl>.

  • src/render.w:78 handles only TypeDeclKind.Struct for brace-body types;
    Alias (:93), Distinct (:100), Enum (:106), DiscEnum (:129) follow; Union
    matches none and hits return out ++ "<unknown type decl>" (:152).
  • The Union layout IS the struct body layout: Parser.parse_struct_body
    (src/Parser.w:1750) and parse_struct_body_block (:1818) both emit
    [count, 3N (name,type,default) triples, N aligns], and union
    construction (Parser.w:1539-1555) uses the same body parser plus trailing
    is_pub/tp_start/tp_count — so the renderer could share the Struct
    branch but does not.

Severity Low: no in-repo callers of any render_* entry point were found
(diagnostic/dump-only surface), so impact is confined to future dump use.
Closed in the same pass as non-findings: the alleged stride-3-vs-4 desync
is refuted (triples and aligns are separate arrays; type_decl_is_pub's
+1+4N lands exactly on the trailing is_pub word both layouts emit);
zero-param fn name: parens and impl header-only rendering are held as
design judgments, not defects.

Activity

  1. ehartford commented on Sep 16, 2026

    @ehartford
    Contributor

    Review: reproduced

    Verdict. The central claim is established by execution on the reported revision and on current main: a union type declaration renders as type Bits<unknown type decl>. Two corrections to the report's framing:

    1. The renderer is reachable from the CLI, not dump-only-in-theory. with ast <file> and with check <file> --dump-ast both call render_module (src/main.w:3045, dispatched from :888-904), and spec §18.5 lists the ast subcommand and --dump-ast as diagnostic surface (implementation-internal, no stability guarantee). So the impact is a wrong diagnostic dump today, not a hypothetical future one.
    2. opaque has the same gap. TypeDeclKind.Opaque (= 5) also has no branch and renders as type Handle<unknown type decl>.

    The report's negative findings (no stride desync; type_decl_is_pub offset lands on the trailing is_pub word for both layouts) are consistent with what I read in the parser and are not contested.

    Tested.

    Source main @ 5809ac1 (2026-09-14); src/render.w has no commits since 450733e
    Compilers with v0.15.2.1 built from 5809ac1 (staging worktree); a compiler built from 450733e with the nightly-20260903 seed. Identical output
    Platform macOS Darwin 25.6.0 arm64

    Input (u.w, spec §16 union spelling; with check u.w prints ok):

    type Pair:
        a: i32
        b: i32
    
    type Bits = union {
        i: i32
        f: f32
    }
    
    type Handle = opaque
    
    fn main:
        print("x")
    

    with ast u.w (rc 0), both compilers:

    type Pair { a: i32, b: i32 }
    type Bits<unknown type decl>
    type Handle<unknown type decl>
    fn main:
      print("x")
    

    Expected: type Bits = union { i: i32, f: f32 } (or the renderer's house style for a brace body) and type Handle = opaque. Actual: the placeholder string for both. The struct control renders correctly. with check u.w --dump-ast prints the same two placeholder lines.

    Root cause. src/render.w:78-152: the NK_TYPE_DECL renderer tests Struct, Alias, Distinct, Enum, DiscEnum in turn and returns out ++ "<unknown type decl>" for anything else; TypeDeclKind has seven values (src/Ast.w:202-209) and Union (6) and Opaque (5) are the two without a branch. The parser builds a union with the same extra layout as a struct body plus the trailing is_pub/tp_start/tp_count words (src/Parser.w:1543-1559), so the Struct branch can be shared with a union keyword; Opaque stores [0, is_pub, tp_start, tp_count] (:1536-1541). Established by source reading plus the run above; no debugger evidence is needed for a missing switch arm.

    AGENTS.md angle. The placeholder is a silent fallback in a diagnostic tool: the dump reports success (rc 0) while emitting text that is not the program. Under "A tool that stayed silent is a bug", a renderer that cannot render a node should fail loudly (non-zero, naming the kind), not print a placeholder.

    Related PRs. None touch src/render.w.

    Recommendation. Fix, small. Acceptance criteria:

    • with ast on the file above round-trips Bits as a union with both fields and Handle as opaque; the output re-parses to the same AST.
    • ephemeral and pub prefixes and type parameters on a union render (the parser stores them at the same trailing offsets as for structs).
    • The fall-through becomes a loud failure (non-zero exit naming the TypeDeclKind value) rather than <unknown type decl>, so the next missing arm cannot hide.
    • A test/ fixture pins the rendered form for every TypeDeclKind value.

    Not tested. @[repr(C)] and generic unions through the renderer (only the plain form above was executed).

  2. ehartford commented on Oct 25, 2026

    @ehartford
    Contributor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): reproduced; src/render.w still has no Union (or Opaque) branch and falls through at :159.

    $ cat u2.w
    type Bits = union { i: i32, f: f32 }
    $ with ast u2.w
    type Bits<unknown type decl>
    

    post-release: it affects only the with ast / --dump-ast diagnostic dump.

  3. added this to the post-v0.16.0 milestone on Oct 28, 2026
  4. ehartford commented on Nov 11, 2026

    @ehartford
    Contributor

    Merged to main ae20d89 (#3248): a union type declaration renders through the struct-body branch as type U = union { … }; fixture test/internals/audit_small_fixes_test.w.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions