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

".".parse() returns Ok(0.0) #30344

Closed
hanna-kruppe opened this issue Dec 11, 2015 · 12 comments · Fixed by #30681
Closed

".".parse() returns Ok(0.0) #30344

hanna-kruppe opened this issue Dec 11, 2015 · 12 comments · Fixed by #30681
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. P-medium Medium priority T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@hanna-kruppe
Copy link
Contributor

This program prints Ok(0) where I would expect an Err(..):

fn main() {
    println!("{:?}", ".".parse::<f64>());
}

If I remember correctly, this behavior has been around since pre-1.0 but it would be good if someone who has multirust available could verify that (at least for 1.0 final if earlier builds are harder to get).

Unfortunately even if we all agree that this behavior is wrong, it may not be worth the potential breakage to fix. For example, recent changes to the integer FromStr format (allowing leading plus) did, surprisingly, break real code. It's quite possible that fixing this wart is not worth the risk.

@hanna-kruppe hanna-kruppe changed the title "." is successfully parsed as float "." is parsed as 0.0 Dec 11, 2015
@hanna-kruppe hanna-kruppe changed the title "." is parsed as 0.0 ".".from_str() returns Ok(0.0) Dec 11, 2015
@hanna-kruppe hanna-kruppe changed the title ".".from_str() returns Ok(0.0) ".".parse() returns Ok(0.0) Dec 11, 2015
@bluss
Copy link
Member

bluss commented Dec 12, 2015

Travis testing says it's present in all versions since 1.0.0 (builds) (code)

@Stebalien
Copy link
Contributor

I'd rather not go down the PHP route and document bugs as features, even minor ones like this. Can we get a crater run? Can't be cratered. Crap.

@alexcrichton
Copy link
Member

triage: I-nominated

@alexcrichton alexcrichton added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Dec 12, 2015
@alexcrichton
Copy link
Member

The libs team discussed this during triage yesterday and the conclusion is that this is pretty reasonable to include in the future as a bugfix, so P-medium for now.

@alexcrichton alexcrichton added P-medium Medium priority and removed I-nominated labels Dec 17, 2015
@hanna-kruppe
Copy link
Contributor Author

This is an ideal E-easy bug, and although it's quite small I can mentor for this if desired. So, someone please tag this E-easy E-mentor.

Details for someone looking to fix this bug:
You'll have to find the correct code path in the parse_decimal function in src/libcore/num/dec2flt/parse.rs and change it to return an error. There is a whole if dedicated to this case, but perhaps there is a more elegant way to rewrite the surrounding code. There's also a test in libcoretest that expect the current (wrong) behavior, it's probably best to change this test to expect an error instead.

@bluss bluss added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels Dec 18, 2015
@yati-sagade
Copy link

E-easy -- can I take this one?

@sfackler
Copy link
Member

Go for it!

@hanna-kruppe
Copy link
Contributor Author

@yati-sagade

Absolutely! If you have questions or run into problems, you can ping me on IRC (my IRC nick is the same as my username here) or if I'm not online on IRC , comment here.

@yati-sagade
Copy link

@rkruppe Thanks :) I'm playing with the code, and this indeed looks easy. However, the build time is insane for such a small change (maybe because libcore compilation forces almost all other modules to compile?). I'm just doing make -j5 -- is there a faster way or I'm stuck with this? :)

Also, do we want to spit a warning at this point or just return Invalid?

@hanna-kruppe
Copy link
Contributor Author

@yati-sagade

There's no way to make build times good, but you can make it less insane by rebuilding less. make -jN check-stage1-coretest will only build the first stage of the bootstrapping process and then enough to run the libcore tests. Since this misses all tests outside of libcore, and AFAIK some test in libstd use parse, you might still want to run make -jN check-stage1-std or even make -jN check if you have the patience. There is also a way to build a full stage1 compiler (to make one-off experiments that need not or should not go into tests), but I keep forgetting what it's called. If you want/need that, hop into #rust-internals and ask how to do it.

As for warning: It would be nice to have a grace period, but I don't see a good way to do it. Since this is a runtime condition, the warning would be shown to the users, not to the developers. Also, how would we even report the warning? Just printing to a running process's stderr is extremely rude — and also not really possibly in libcore. @alexcrichton what do you think?

bors added a commit that referenced this issue Jan 4, 2016
Make `".".parse::<f32>()` and `".".parse::<f64>()` return Err

This fixes #30344.

This is a [breaking-change], which the libs team have classified as a
bug fix.
@ghost
Copy link

ghost commented Jan 5, 2016

Sorry that I just jumped in and did this @yati-sagade, I didn't realise someone else was doing it until I was opening the PR.

@yati-sagade
Copy link

@Toby-s No problem. I didn't realize that returning Err was what we were going to do (per above discussion).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. P-medium Medium priority T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants