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
rkruppe opened this Issue Dec 11, 2015 · 12 comments

Comments

Projects
None yet
9 participants
@rkruppe
Copy link
Member

rkruppe commented Dec 11, 2015

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.

@rkruppe rkruppe changed the title "." is successfully parsed as float "." is parsed as 0.0 Dec 11, 2015

@rkruppe rkruppe changed the title "." is parsed as 0.0 ".".from_str() returns Ok(0.0) Dec 11, 2015

@rkruppe rkruppe changed the title ".".from_str() returns Ok(0.0) ".".parse() returns Ok(0.0) Dec 11, 2015

@apasel422 apasel422 added the A-libs label Dec 12, 2015

@bluss

This comment has been minimized.

Copy link
Contributor

bluss commented Dec 12, 2015

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

@Stebalien

This comment has been minimized.

Copy link
Contributor

Stebalien commented Dec 12, 2015

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

This comment has been minimized.

Copy link
Member

alexcrichton commented Dec 12, 2015

triage: I-nominated

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Dec 17, 2015

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 and removed I-nominated labels Dec 17, 2015

@rkruppe

This comment has been minimized.

Copy link
Member Author

rkruppe commented Dec 18, 2015

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.

@yati-sagade

This comment has been minimized.

Copy link

yati-sagade commented Dec 18, 2015

E-easy -- can I take this one?

@sfackler

This comment has been minimized.

Copy link
Member

sfackler commented Dec 18, 2015

Go for it!

@rkruppe

This comment has been minimized.

Copy link
Member Author

rkruppe commented Dec 18, 2015

@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

This comment has been minimized.

Copy link

yati-sagade commented Dec 23, 2015

@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?

@rkruppe

This comment has been minimized.

Copy link
Member Author

rkruppe commented Dec 23, 2015

@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

Auto merge of #30681 - Toby-S:master, r=bluss
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.

@bors bors closed this in #30681 Jan 5, 2016

@Toby-S

This comment has been minimized.

Copy link
Contributor

Toby-S 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

This comment has been minimized.

Copy link

yati-sagade commented Jan 5, 2016

@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
You can’t perform that action at this time.