Skip to content

[Repo Assist] Fix #1221 — JsonValue.Float always infers as float, not int/int64#1628

Closed
github-actions[bot] wants to merge 1 commit intomainfrom
repo-assist/fix-issue-1221-float-exponential-inference-bd4f4ce4887e096a
Closed

[Repo Assist] Fix #1221 — JsonValue.Float always infers as float, not int/int64#1628
github-actions[bot] wants to merge 1 commit intomainfrom
repo-assist/fix-issue-1221-float-exponential-inference-bd4f4ce4887e096a

Conversation

@github-actions
Copy link
Contributor

🤖 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, or 2.34567E5 were incorrectly inferred as int or int64 instead of float.

Root Cause

TextConversions.AsDecimal uses NumberStyles.Currency, which does not include AllowExponent. This means any JSON number that uses exponent notation fails Decimal parsing and falls through to JsonValue.Float. Previously, JsonInference.inferType would then check isIntegerFloat f (i.e., Math.Round f = f) and promote the value to int or int64 if the float happened to be a whole number. So 0.1e1 = 1.0 would end up inferred as int.

Fix

Remove the integer-promotion branches for JsonValue.Float entirely (JsonInference.fs lines 52–63 before this change). JsonValue.Float is only produced for numbers that cannot be represented as Decimal (exponential notation or out-of-range values), 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 — unchanged behaviour for the common case.

Also removes now-unused inRangeFloat and isIntegerFloat helpers.

Breaking change note

Arrays containing exponential-notation numbers alongside other numbers may be inferred as float[] rather than decimal[]. Concretely, [1, 2.34567E5, 3.14] was previously inferred as decimal[] (because 2.34567E5 was promoted to int, which unified to decimal with 3.14); it is now correctly inferred as float[]. The ExponentialDecimalProvider test is updated accordingly.

Changes

File Change
src/FSharp.Data.Json.Core/JsonInference.fs Remove JsonValue.Floatint/int64 inference; remove unused helpers
tests/FSharp.Data.DesignTime.Tests/InferenceTests.fs Add regression test for #1221
tests/FSharp.Data.Tests/JsonProvider.fs Update ExponentialDecimalProvider test to reflect corrected float[] inference

Test Status

  • FSharp.Data.Tests — all 253 tests pass (including updated ExponentialDecimalProvider test)
  • FSharp.Data.DesignTime.Tests469 pass, 18 failures (same 18 infrastructure failures as main — network-blocked URL tests and an XSD test, pre-existing and unrelated to this change)
  • New regression test Exponential-notation numbers infer as float not int (issue 1221) — ✅ passes

Closes #1221

Generated by Repo Assist

To install this workflow, run gh aw add githubnext/agentics/workflows/repo-assist.md@828ac109efb43990f59475cbfce90ede5546586c. View source at https://github.com/githubnext/agentics/tree/828ac109efb43990f59475cbfce90ede5546586c/workflows/repo-assist.md.

Warning

⚠️ Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • schemas.microsoft.com
  • tomasp.net

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>
@github-actions
Copy link
Contributor Author

✅ Pull request created: #1628

@dsyme dsyme marked this pull request as ready for review February 23, 2026 01:48
@dsyme dsyme closed this Feb 23, 2026
@dsyme dsyme reopened this Feb 23, 2026
@dsyme
Copy link
Contributor

dsyme commented Feb 23, 2026

The change is too invasive, see original bug which I've closed

@dsyme dsyme closed this Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Numeric inference in 3.0.0 appears broken

1 participant