Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coerce int values into float when expected #1150

Merged
merged 5 commits into from
Nov 17, 2021
Merged

Coerce int values into float when expected #1150

merged 5 commits into from
Nov 17, 2021

Conversation

ghostdogpr
Copy link
Owner

@ghostdogpr ghostdogpr commented Nov 17, 2021

Also did a bit of unrelated cleanup.

variables = Some(
Map(
"input" -> InputValue.ObjectValue(
Map("float" -> Value.IntValue(42))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, this strikes me as a bit odd since JSON only supports floats 🤔 I would probably have expected the coercion to be the other way around...

But perhaps we have some smartness in the parser to parse numbers without decimals as ints so we need to deal with both cases?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parser would parse into a FloatValue only if there is a dot or a e for exponent.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In scala 2. The scala 3 one checks for int before float so the result is the same.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the spec, float should not be coerced into int.

@ghostdogpr ghostdogpr merged commit 3086e20 into master Nov 17, 2021
@ghostdogpr ghostdogpr deleted the coerce_floats branch November 17, 2021 10:28
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.

2 participants