Skip to content

schemagen: an OPEN CUE struct ({a!: int, ...}) is emitted as map[string]any, losing every field #362

Open

Description

@aitrawog

Finding

schemagen/schemaparams emits an open CUE struct — a required field plus an ellipsis — as map[string]any, losing every field it declares. Its closed twin is emitted correctly, so the ellipsis alone flips the shape from a struct to a map.

Isolated, through schemaparams.Generate (the same pipeline charly task cue-gen runs):

// an OPEN struct: a required field plus an ellipsis
#Open: {a!: int, ...}
// its closed twin
#Closed: {a!: int}
// and a plain ellipsis-keyed map, which IS a map
#Ellip: {[string]: int}
// an OPEN struct: a required field plus an ellipsis
type Open map[string]any /* CUE top */

// its closed twin
type Closed struct {
	A int64 `yaml:"a,omitempty" json:"a"`
}

// and a plain ellipsis-keyed map, which IS a map
type Ellip map[string]int64

Cause

emitStructKind asks val.LookupPath(cue.MakePath(cue.AnyString)) whether the value is a map (gotypes.go:358). An ellipsis makes [string]: _ resolve, so the branch fires, prints map[string], and then emits the ellipsis's element — which is the CUE top type, spelled any /* CUE top */. The declared field a! is never visited. The check cannot tell "an ellipsis-keyed MAP" ({[string]: T}) from "an OPEN STRUCT" ({a!: T, ...}); both answer the lookup.

Why it matters

An open struct is a normal CUE shape — any definition written with a trailing ... (which is how @experiment(explicitopen) is avoided when a closed definition must be widened), and any definition built that way by the design's {x...} spellings, loses its fields in Go. It is the same class as #271 (a shape that silently degrades instead of failing), and it is what stopped the capability port (#360) from opening #CountNeed/#SizeNeed/#MountNeed with an ellipsis: the leasable need entry would have become map[string]any rather than a struct.

Asks

  1. Tell the two apart: an ellipsis-keyed map has no named fields, an open struct has some. When named fields exist, emit the STRUCT and ignore the ellipsis (Go has no open-struct type, and the field set is what a consumer reads).
  2. A test with both fixtures above, since the closed twin already proves the struct path works.

Filed while addressing the second review round on #360, where the workaround was to declare the field on the definition instead of opening it.

Agent: audit-protocol
Assisted-by: DeepSeek Harness ollama-cloud/deepseek-v4.1-flash (syntax check only)

Activity

  1. added
    category:runtime
    type:fix
    on Nov 23, 2026
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

    category:runtimetype:fix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions