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).
48 lines
2.2 KiB
Plaintext
48 lines
2.2 KiB
Plaintext
error: type mismatch: constant 'N' is declared 'string' but its initializer is an integer literal
|
|
--> examples/1143-diagnostics-typed-module-const-mismatch.sx:24:15
|
|
|
|
|
24 | N : string : 4; // integer literal where a string is annotated
|
|
| ^
|
|
|
|
error: type mismatch: constant 'F' is declared 's64' but its initializer is a string literal
|
|
--> examples/1143-diagnostics-typed-module-const-mismatch.sx:25:15
|
|
|
|
|
25 | F : s64 : "x"; // string literal where an integer is annotated
|
|
| ^^^
|
|
|
|
error: type mismatch: constant 'B' is declared 's64' but its initializer is a boolean literal
|
|
--> examples/1143-diagnostics-typed-module-const-mismatch.sx:26:15
|
|
|
|
|
26 | B : s64 : true; // boolean literal where an integer is annotated
|
|
| ^^^^
|
|
|
|
error: cannot implicitly narrow non-integral float '1.5' to 's64'; use an explicit cast (`xx`/`cast`)
|
|
--> examples/1143-diagnostics-typed-module-const-mismatch.sx:27:15
|
|
|
|
|
27 | G : s64 : 1.5; // float literal where an integer is annotated
|
|
| ^^^
|
|
|
|
error: type mismatch: constant 'E' is declared 'string' but its initializer is an integer expression
|
|
--> examples/1143-diagnostics-typed-module-const-mismatch.sx:28:15
|
|
|
|
|
28 | E : string : M + 2; // integer EXPRESSION where a string is annotated
|
|
| ^^^^^
|
|
|
|
error: type mismatch: constant 'V' is declared 'string' but its initializer is an integer expression
|
|
--> examples/1143-diagnostics-typed-module-const-mismatch.sx:29:15
|
|
|
|
|
29 | V : string : -M; // integer (unary) expression where a string is annotated
|
|
| ^^
|
|
|
|
error: cannot implicitly narrow non-integral float '2.5' to 's64'; use an explicit cast (`xx`/`cast`)
|
|
--> examples/1143-diagnostics-typed-module-const-mismatch.sx:30:15
|
|
|
|
|
30 | BAD : s64 : M + 0.5; // mixed int+float (int LHS) → f64, rejected vs s64
|
|
| ^^^^^^^
|
|
|
|
error: cannot implicitly narrow non-integral float '2.5' to 's64'; use an explicit cast (`xx`/`cast`)
|
|
--> examples/1143-diagnostics-typed-module-const-mismatch.sx:31:15
|
|
|
|
|
31 | BAD2 : s64 : 0.5 + M; // mixed float+int (float LHS) → f64, rejected vs s64 — order-independent
|
|
| ^^^^^^^
|