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
pub const still requires an explicit type; the value already forces it #2101
error: public const declarations require an explicit type annotation
--> game.w:12:21
12 | pub const ENEMY_CAP = 2000
The rule comes from aa6e50ae ("Allow inferred private and local const", #353, Jun 9), which allowed inference for private and local const and kept it out of pub const (test/compile_errors/err_pub_const_requires_type.w). The idiomatic guide still says "const requires a type annotation" (docs/spec/guide/with-idiomatic-guide.md:190).
Why it should go (mission.md)
The value forces exactly one type.2000 is i32, 1.0 / 120.0 is f64, and 0x28DEu16 is u16. Writing : i32 repeats "what the program has already determined", which the mission calls a compiler failure. The type is no less fixed for being visible to another module.
The function rule already moved. Public functions infer their return types now ("public return inference", Sep 25). A public const is the simpler case: its type comes from one literal or constant expression, not from control flow.
It leaves a two-tier style. WIPE's private constants now read const CELL_SIZE = 64, but its public ones must read pub const ENEMY_CAP: i32 = 2000.
A literal suffix covers the cases where the wanted type differs from the literal's default (1u32, 0x28DEu16), so the annotation is never the only way to say it.
Expected
pub const NAME = <constant expression> takes the expression's type, like a private const. Update the guide's sentence to match.
Activity
spec v7.24 (D95): let _ drops; pub const takes its value's type; ?? b…
D95 + D96: let _ drops; pub const takes its value's type; ?? below |>…
ehartford commentedon Oct 5, 2026
Fixed on main by stack #2196 (merged as efb765c), battery green on a21e326; the regression test for it landed with the fix.