[refurb] Mark int and bool cases for Decimal.from_float as safe fixes in FURB164 tests#19468
Conversation
| } | ||
| replacement_arg = chars.into_iter().collect(); | ||
| } | ||
| } |
There was a problem hiding this comment.
Does this work for float("\x2dnan") or float("\N{HYPHEN-MINUS}nan")? Cf. #16771.
There was a problem hiding this comment.
Yes, it covers both of those cases
There was a problem hiding this comment.
Could we add tests for those cases? I also think we could use the return value of as_non_finite_float_string_literal just above this instead of doing some of the manual manipulation ourselves. That should normalize the result so that we can just compare against "-nan" directly.
ntBre
left a comment
There was a problem hiding this comment.
Thanks! Just a couple of suggestions
| ) | ||
| }) | ||
| .unwrap_or_default() | ||
| .unwrap_or((false, false)) |
There was a problem hiding this comment.
I think this should be equivalent, but it's probably more readable, even though I think I suggested the old version 😆
| } | ||
| replacement_arg = chars.into_iter().collect(); | ||
| } | ||
| } |
There was a problem hiding this comment.
Could we add tests for those cases? I also think we could use the return value of as_non_finite_float_string_literal just above this instead of doing some of the manual manipulation ourselves. That should normalize the result so that we can just compare against "-nan" directly.
|
|
||
| match (method_name, constructor) { | ||
| // Decimal.from_float accepts int, bool, float | ||
| // Decimal.from_float: Only int or bool are safe (float is unsafe due to FloatOperation trap) |
There was a problem hiding this comment.
We might want to update the name of this function and also the comment where it's called. is_valid made me think we would bail out without a diagnostic or without a fix if the result is invalid, but it's really just checking the fix safety.
|
ntBre
left a comment
There was a problem hiding this comment.
Thanks! Just one more tiny nit that I'll probably just apply and then merge this.
Summary
Fixes #19460