Skip to content

A field with a default may omit its type; a numeric default takes the type its uses demand (D89, #2097) - #2105

Merged
ehartford merged 3 commits into
untyped-const-2096from
field-default-2097
Oct 5, 2026
Merged

ehartford merged 3 commits into
untyped-const-2096from
field-default-2097

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Implements spec v7.20 §4.3 (D89). Fixes #2097.

  • Parser: name = default; the type is what the default makes evident (a literal's, a struct literal's). A default that does not say (a call such as Vec.new()) is an error asking for the type — narrower than the spec's "the type of its default" for calls; noted as remaining.
  • Sema: an unsuffixed numeric default takes the type the field's uses in the program demand; none → i32/f64; two → error at the field. Done by checking such a program twice.

Stage1 only so far — no gate, no battery.

Eric Hartford added 2 commits October 4, 2026 16:35
Spec v7.20 §4.3: `type T { ticks = 0, alive = true, pos = Vector2 { … } }`.
The field has the type its default makes evident: a literal's, a struct
literal's. A default that does not (a call) is an error asking for the
type. An unsuffixed numeric default is i32 or f64 for now; taking the type
the field's uses demand is the next change.
…and (D89, #2097)

Spec v7.20 §4.3. A program with such a field is checked twice: once to
hear what the field's uses demand (each field is a distinct alias of its
default type, so an owned demand or a peer operand names its field; nothing
is reported), then with every field at the type decided. No demand leaves
`i32` or `f64`; two different demands are an error at the field that asks
for its type. A program without such a field is checked once, as before.
@ehartford
ehartford added this pull request to stack #2106 October 4, 2026 23:41
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery GREEN for stack #2106 at d5c7b59 (macOS arm64, seed-driven, with run tools/battery.w): gate rc=0 912s, uat rc=0 23s, battery-checks rc=0 191s.

@ehartford
ehartford marked this pull request as ready for review October 5, 2026 00:05
@ehartford
ehartford merged commit e382b95 into main Oct 5, 2026
@ehartford
ehartford deleted the field-default-2097 branch October 5, 2026 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A struct field with a default should infer its type: type T { ticks = 0 } fails to parse

1 participant