Skip to content

What a sole enum field means, decided by measurement — and the entanglement is gone #2712

Description

@gHashTag

#2710 refuted rewriting the shape; #2711 showed the neighbouring fix was blocked by the same undecided question. The question is answerable by measuring the corpus rather than by choosing.

Across all 497 specs, every struct containing a field named enum:

count
enum is the sole field, value a bare-identifier list 9 [Ascending, Descending]
enum is the sole field, value empty 12 no variant names exist
enum is the sole field, value a quoted list 1 ["RED", "BLACK"]
enum alongside other fields 1 tools/schema.t27 ParameterSchema

Zero overlap. The one genuine record — the refuter's counter-example, whose enum field holds a type — is exactly the case a sole-field rule excludes. So:

A struct whose sole field is enum with a bare-identifier list is an enum declaration. An enum field alongside others is a field.

That is decided by the corpus, not by preference, and it unblocks both fixes at once.

Landed together, because separately each regresses

  1. fold_sole_enum_field — 9 declarations become real Zig enums.
  2. A keyword is a legal struct field name when a colon follows — 23 fields in 21 specs, 22 of them enum. The colon is the discriminator so enum ErrorCode { in the braced dialect is not read as a field.
  3. fold_enum_type_marker — the other generator shape, enum_type : "enum", values : , Zeros : Auto, .... 4 declarations, none of which could have a dependent: they emitted enum_type: enum, values: void, which is not valid Zig at all.

Alone, (2) cost five specs (#2711). With (1) it costs none, because those five stop being structs.

Measured:

before after
ast-check valid 290 293
ast-check errors 594 591
specs worse / better 0 / 3
parse gate 105 105 events / 0 lost, holds

ParameterSchema keeps @"enum": ?[any]. SortOrder is enum { Ascending, Descending }. PaddingMode is enum { Zeros, Reflect, Replicate, Circular }.

The pinning tests now fail, as they should

The five specs' tests read @typeInfo(X).@"struct".fields.len and @FieldType(X, "Ascending") — written by my own agents two iterations ago to move a flat assertion count, and they pinned the accidental struct shape. They now report access of union field 'struct' while field 'enum' is active.

That is the fix working. Updating them to assert enum properties is the next commit, not a separate concern — a defect repair that leaves its pinning tests red is only half done.

Not folded

The 12 declarations whose enum field is empty carry no variant names in the source. A rule could only produce enum {}, which recovers no meaning. They need the specs repaired upstream.

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

    needs-boundaryNo '## Boundary' section, so the Queen can reserve nothing for it and no bee can take it

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions