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
An unannotated float const takes f64 instead of its use's type; using it as f32 is rejected as narrowing #2096
const A = 1.0 / 120.0
const B = 12.0
fn takes32(x: f32) -> f32: x
fn main:
let y = takes32(A)
let z: f32 = B
print(f"{y} {z}")
error: implicit float narrowing from `f64` to `f32`; use an explicit `as` cast (§4.2.6)
--> infer.w:7:21
7 | let y = takes32(A)
error: implicit float narrowing from `f64` to `f32`; use an explicit `as` cast (§4.2.6)
--> infer.w:8:18
8 | let z: f32 = B
Expected
Both lines compile, with A and B taking f32 from their use. An unsuffixed float literal is f64 only when nothing says otherwise. Here the f32 parameter and the f32 binding say otherwise. The constants have no type of their own to narrow from: the language's inference should give them f32, as it would give the literals themselves (takes32(1.0 / 120.0) and let z: f32 = 12.0 are fine).
Impact
A raylib program, where everything is f32 (Vector2, DrawCircleV), has to annotate every float constant (const SHIP_SPEED: f32 = 320.0) or cast at each use. Found writing a tutorial game for the WIPE repo (withlang-dev/wipe).
Activity
Spec v7.20: an unsuffixed const has no numeric type of its own; a fie…
sema: a const of unsuffixed numeric literals has no numeric type of i…
Blog: making a game from scratch in With using raylib, and a gameplay…
Spec changelog: the NON-COMPLIANT sentences of fourteen entries whose…