Skip to content

sema: a const of unsuffixed numeric literals has no numeric type of its own (D88, #2096) - #2104

Merged
ehartford merged 1 commit into
mainfrom
untyped-const-2096
Oct 5, 2026
Merged

ehartford merged 1 commit into
mainfrom
untyped-const-2096

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Implements spec v7.20 §4.2.1 (D88). Fixes #2096. Also fixes a folded float constant losing precision (17 decimals, not 17 significant digits). Behavior and compile-error tests added; verified on stage1 only so far — no gate, no battery.

…ts own (D88, #2096)

Spec v7.20 §4.2.1. `const B = 12.0` was f64 at every use, so
`let z: f32 = B` was implicit narrowing. An unannotated const whose
initializer is unsuffixed numeric literals, operators on them and other
such constants is now typed at each use as that initializer would be
there: the comptime transform keeps the written initializer beside the
folded value, Sema types the use from its context (and reports a value
that does not fit), and MIR lowers the initializer at that type, so f32
arithmetic is f32 arithmetic.

Found on the way: a folded float constant was written back with 17 digits
after the decimal point, not 17 significant digits, so
`const STEP: f64 = 1.0 / 120.0` was not equal to `1.0 / 120.0`. It is
written in scientific notation now.
@ehartford
ehartford added this pull request to stack #2106 October 4, 2026 23:41
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery GREEN for stack #2106 at d5c7b59 (macOS arm64, seed-driven, with run tools/battery.w): gate rc=0 912s, uat rc=0 23s, battery-checks rc=0 191s.

@ehartford
ehartford marked this pull request as ready for review October 5, 2026 00:05
@ehartford
ehartford merged commit 947c093 into main Oct 5, 2026
@ehartford
ehartford deleted the untyped-const-2096 branch October 5, 2026 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

An unannotated float const takes f64 instead of its use's type; using it as f32 is rejected as narrowing

1 participant