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
Sema accepts f64 where i32 is expected; the mistake surfaces in codegen with no file, line or hint #1220
Spec. §4 numeric conversions: widening is implicit, a narrowing is spelled with as. Float to integer drops the fraction and leaves two meanings (truncate or round), so the programmer spells it.
fn circle(x: i32, y: i32, r: f32) -> f32: r + (x + y) as f32
fn main:
let x = 12.7
print(f"{circle(x, x, 1.0)}")
Actual.
error: wrong argument type actual=f64 expected=i32 fn=main
error: wrong argument type actual=f64 expected=i32 fn=main
error: code generation failed
No file, no line, no span, no suggestion: Sema let it through and codegen's type enforcement caught it.
Exact lines.src/Sema.w:6965-6966 (types_compatible_fast) and src/Sema.w:7214-7215 (the frozen twin): if exp_k == TY_INT and act_k == TY_FLOAT: return 1. The reverse arm (int where float is expected) is the legitimate widening and stays.
Expected. A Sema diagnostic on the argument: expected i32, found f64, with a note that the conversion drops the fraction and the two spellings (x as i32 truncates; x.round() as i32 rounds).
Found by. Auditing the casts in the raylib spiral example: seven of its nine casts are unnecessary (int widens to float, a float literal takes the parameter's type, f64 passes to an f32 parameter); DrawCircle(x as i32, y as i32, ...) are the two that are needed, and omitting one gives the output above.
Scope note. Removing the arm needs a sweep of src/, lib/std, tests and the audit-probe generators for code that relies on it; its own batch.
Same class, second instance (found probing variable widths in the spiral example):
fn main:
let t = 1.25 as f32
let wants_bool: bool = t
Sema accepts the float-to-bool binding; it is caught by the typed MIR verifier with an internal message and no suggestion:
error: invalid MIR before codegen: use rvalue type is incompatible with assign destination (dest ty=13 kind=3, src ty=11 kind=2)
Expected: a Sema diagnostic at the binding (expected bool, found f32). The fix for this issue should enumerate Sema's scalar compatibility arms in one pass (int/float/bool in every direction, at argument, binding, return and field-init sites) rather than patch the one arm named above.
Activity
ehartford commentedon Sep 20, 2026
Same class, second instance (found probing variable widths in the spiral example):
Sema accepts the float-to-bool binding; it is caught by the typed MIR verifier with an internal message and no suggestion:
Expected: a Sema diagnostic at the binding (
expected bool, found f32). The fix for this issue should enumerate Sema's scalar compatibility arms in one pass (int/float/bool in every direction, at argument, binding, return and field-init sites) rather than patch the one arm named above.