Repository navigation
sema: a const of unsuffixed numeric literals has no numeric type of its own (D88, #2096) - #2104
Merged
Merged
Conversation
…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.
Contributor
Author
|
Battery GREEN for stack #2106 at d5c7b59 (macOS arm64, seed-driven, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.