Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upAdded extra condition to stop '-' or '+' returning a `Float` from `String.toInt`. #834
Conversation
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
process-bot
Feb 3, 2017
Thanks for the pull request! Make sure it satisfies this checklist. My human colleagues will appreciate it!
Here is what to expect next, and if anyone wants to comment, keep these things in mind.
process-bot
commented
Feb 3, 2017
|
Thanks for the pull request! Make sure it satisfies this checklist. My human colleagues will appreciate it! Here is what to expect next, and if anyone wants to comment, keep these things in mind. |
ChrisWellsWood
changed the title from
Added extra condition to catch '-' or '+'.
to
Added extra condition to stop '-' or '+' returning NaN from `toInt`.
Feb 3, 2017
ChrisWellsWood
changed the title from
Added extra condition to stop '-' or '+' returning NaN from `toInt`.
to
Added extra condition to stop '-' or '+' returning a `Float` from `String.toInt`.
Feb 3, 2017
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
evancz
Mar 26, 2017
Member
Nice find! That boolean expression is getting out of control, but I'm not really sure how to simplify it in a nice way. Anyway, thanks for the fix!
|
Nice find! That boolean expression is getting out of control, but I'm not really sure how to simplify it in a nice way. Anyway, thanks for the fix! |
ChrisWellsWood commentedFeb 3, 2017
•
edited
Edited 1 time
-
ChrisWellsWood
edited Feb 3, 2017 (most recent)
Current Issue
Currently
String.toIntcan return aFloat, as the JavaScript functionparseIntwill returnNaN(which is typeFloatin Elm) if you supply it with '+' or '-'. This will get around the type checker, so the compiler will think that the 'NaN' is anInt. See #831 for more details of the bug.Solution
I've added a new condition so that an error will be raised if the input string is a single '-' or '+' character.
If you'd like to check the logic, I've mocked it up on repl.it.