[Repo Assist] Fix #1221 — JsonValue.Float always infers as float, not int/int64#1628
Closed
github-actions[bot] wants to merge 1 commit intomainfrom
Closed
Conversation
Previously, exponential-notation JSON numbers such as `0.1e1` or `1e3` were stored as `JsonValue.Float` (because `TextConversions.AsDecimal` uses `NumberStyles.Currency` which excludes `AllowExponent`), then incorrectly promoted to `int` or `int64` when the float value happened to be a whole number (`isIntegerFloat`). This caused arrays like `[0.1e1, 0.2e1]` to infer as `int[]` instead of `float[]`. The fix removes the integer-promotion branches for `JsonValue.Float` entirely. `JsonValue.Float` is only produced for numbers that cannot be represented as `Decimal` (e.g., exponential notation), so it is semantically correct to always infer them as `float`. `JsonValue.Number` (plain decimal numbers like `1`, `42`, `3.14`) continues to be promoted to `int`/`int64`/`decimal` as before. Also removes the now-unused `inRangeFloat` / `isIntegerFloat` helpers. Regression test added in InferenceTests.fs. The ExponentialDecimalProvider test in JsonProvider.fs is updated to reflect the corrected inference (float[] not decimal[]). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Author
|
✅ Pull request created: #1628 |
3 tasks
Contributor
|
The change is too invasive, see original bug which I've closed |
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.
🤖 This is an automated draft PR from Repo Assist, an AI assistant.
Summary
Fixes the long-standing inference bug (#1221) where exponential-notation JSON numbers such as
0.1e1,1e3, or2.34567E5were incorrectly inferred asintorint64instead offloat.Root Cause
TextConversions.AsDecimalusesNumberStyles.Currency, which does not includeAllowExponent. This means any JSON number that uses exponent notation fails Decimal parsing and falls through toJsonValue.Float. Previously,JsonInference.inferTypewould then checkisIntegerFloat f(i.e.,Math.Round f = f) and promote the value tointorint64if the float happened to be a whole number. So0.1e1 = 1.0would end up inferred asint.Fix
Remove the integer-promotion branches for
JsonValue.Floatentirely (JsonInference.fslines 52–63 before this change).JsonValue.Floatis only produced for numbers that cannot be represented asDecimal(exponential notation or out-of-range values), so it is semantically correct to always infer them asfloat.JsonValue.Number(plain decimal numbers like1,42,3.14) continues to be promoted toint/int64/decimalas before — unchanged behaviour for the common case.Also removes now-unused
inRangeFloatandisIntegerFloathelpers.Breaking change note
Arrays containing exponential-notation numbers alongside other numbers may be inferred as
float[]rather thandecimal[]. Concretely,[1, 2.34567E5, 3.14]was previously inferred asdecimal[](because2.34567E5was promoted toint, which unified todecimalwith3.14); it is now correctly inferred asfloat[]. TheExponentialDecimalProvidertest is updated accordingly.Changes
src/FSharp.Data.Json.Core/JsonInference.fsJsonValue.Float→int/int64inference; remove unused helperstests/FSharp.Data.DesignTime.Tests/InferenceTests.fstests/FSharp.Data.Tests/JsonProvider.fsExponentialDecimalProvidertest to reflect correctedfloat[]inferenceTest Status
FSharp.Data.Tests— all 253 tests pass (including updatedExponentialDecimalProvidertest)FSharp.Data.DesignTime.Tests— 469 pass, 18 failures (same 18 infrastructure failures asmain— network-blocked URL tests and an XSD test, pre-existing and unrelated to this change)Exponential-notation numbers infer as float not int (issue 1221)— ✅ passesCloses #1221
Warning
The following domains were blocked by the firewall during workflow execution:
schemas.microsoft.comtomasp.net