You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A struct field with a default should infer its type: type T { ticks = 0 } fails to parse #2097
type T { ticks = 0, rate = 2.5, alive = true }
fn main:
let t = T {}
print(f"{t.ticks} {t.rate} {t.alive}")
error: expected ':'
--> fieldinfer.w:1:16
1 | type T { ticks = 0, rate = 2.5 }
| ^
Expected
A field with a default takes its type from the default, as let and const do. ticks = 0 is an i32 field, and alive = true is a bool field. A float default follows the same contextual rule as a float const (see #2096): rate is f32 when its uses demand f32, and f64 only when nothing says otherwise.
An explicit type stays available, and necessary, where the default alone doesn't decide it. Examples are seed: u32 = 2463534242 (unsigned wrap-around arithmetic) and a field with no default (rocks: Vec[Rock]).
Why
Writing ticks: i32 = 0 repeats what the literal already says. In a raylib program the noise is everywhere: ship: Vector2 = Vector2 { x: 480.0, y: 300.0 }, radius: f32 = 10.0, alive: bool = true. Found writing a tutorial game for withlang-dev/wipe. Related: #2096.
Correction to the issue text: seed: u32 = 2463534242 isn't an example of a field that needs an explicit type. By convention the literal carries its type: seed = 2463534242u32, which already parses as a literal today. The remaining case for an explicit field type is a field with no default, such as rocks: Vec[Rock].
Activity
ehartford commentedon Oct 4, 2026
Correction to the issue text:
seed: u32 = 2463534242isn't an example of a field that needs an explicit type. By convention the literal carries its type:seed = 2463534242u32, which already parses as a literal today. The remaining case for an explicit field type is a field with no default, such asrocks: Vec[Rock].Spec v7.20: an unsuffixed const has no numeric type of its own; a fie…
A field with a default may omit its type; a numeric default takes the…
Spec changelog: the NON-COMPLIANT sentences of fourteen entries whose…