Completes issue 0095 (attempt 2). The attempt-1 coerce arm only caught a direct `const_float` literal, so a non-integral const-folded float EXPRESSION still truncated silently at a typed local / field default / param default: M :: 2; local : s64 = M + 0.5; // → 2 (silent truncation — BUG; now ERRORS) fld : s64 = M + 0.5; // field default — same take(x : s64 = M + 0.5) // param default — same while the typed-CONST site already errored. The integral expression (`M + 2.0` → 4) folded but the runtime/explicit-cast paths must stay untouched. Fix: - New `program_index.evalConstFloatExpr` — the f64 counterpart to `evalConstIntExpr`, delegating every integer subtree back to it (no parallel integer logic) and adding only the float literal / unary-negate / `+ - * /` arms. Pure (no diagnostics, no resolution side effects). - `Lowering.foldComptimeFloatInit` applies the unified rule to a typed-binding initializer EXPRESSION: an integral comptime float folds to its `constInt`, a non-integral one errors, a genuine runtime float / `xx`-cast falls through to the normal path. It runs `evalConstFloatExpr` FIRST (pure) so a `$pack[i]` argument is never spuriously type-resolved outside an active binding, then gates on `isFloat(inferExprType)` so a plain comptime int is left alone. Wired into the typed-local path, the three struct field-default sites (via a shared `lowerCoercedDefault`), and the call-argument loop (covers expanded param defaults). - One `Lowering.diagNonIntegralNarrow` now emits the narrowing wording at all five sites (coerce arm, global init, const-expr value, the typed-binding sites, and the typed-const path). The typed-CONST non-integral diagnostic therefore reads "cannot implicitly narrow non-integral float …" instead of the stale "initializer is a float literal / floating-point expression". Tests: examples/1146 (negative) extended with non-integral const-EXPRESSION cases at local/field/param; examples/0168 (positive) extended with integral const-EXPRESSION folds and `xx (M + 0.5)` truncation; examples/1143 reconciled to the aligned const message (G/BAD/BAD2 stay errors); unit test `evalConstFloatExpr folds comptime float expressions`. Full gate green (447).
36 lines
1.7 KiB
Plaintext
36 lines
1.7 KiB
Plaintext
error: cannot implicitly narrow non-integral float '1.5' to 's64'; use an explicit cast (`xx`/`cast`)
|
|
--> examples/1146-diagnostics-nonintegral-float-to-int.sx:29:16
|
|
|
|
|
29 | y : s64 = 1.5; // non-integral float LITERAL local → error
|
|
| ^^^
|
|
|
|
error: cannot implicitly narrow non-integral float '2.5' to 's64'; use an explicit cast (`xx`/`cast`)
|
|
--> examples/1146-diagnostics-nonintegral-float-to-int.sx:30:16
|
|
|
|
|
30 | ye : s64 = M + 0.5; // non-integral const-EXPRESSION local → error
|
|
| ^^^^^^^
|
|
|
|
error: cannot implicitly narrow non-integral float '3.5' to 's64'; use an explicit cast (`xx`/`cast`)
|
|
--> examples/1146-diagnostics-nonintegral-float-to-int.sx:21:16
|
|
|
|
|
21 | f : s64 = 3.5; // non-integral float LITERAL field default → error
|
|
| ^^^
|
|
|
|
error: cannot implicitly narrow non-integral float '2.5' to 's64'; use an explicit cast (`xx`/`cast`)
|
|
--> examples/1146-diagnostics-nonintegral-float-to-int.sx:22:16
|
|
|
|
|
22 | fe : s64 = M + 0.5; // non-integral const-EXPRESSION field default → error
|
|
| ^^^^^^^
|
|
|
|
error: cannot implicitly narrow non-integral float '2.5' to 's64'; use an explicit cast (`xx`/`cast`)
|
|
--> examples/1146-diagnostics-nonintegral-float-to-int.sx:25:23
|
|
|
|
|
25 | badLit :: (x : s64 = 2.5) -> s64 { return x; } // non-integral LITERAL param default → error
|
|
| ^^^
|
|
|
|
error: cannot implicitly narrow non-integral float '2.5' to 's64'; use an explicit cast (`xx`/`cast`)
|
|
--> examples/1146-diagnostics-nonintegral-float-to-int.sx:26:23
|
|
|
|
|
26 | badExpr :: (x : s64 = M + 0.5) -> s64 { return x; } // non-integral const-EXPR param default → error
|
|
| ^^^^^^^
|