Skip to content

strings like ".Exxx" are not valid floats/doubles #6726

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

Merged
merged 3 commits into from
Jun 6, 2018

Conversation

martijnhoekstra
Copy link
Contributor

@martijnhoekstra martijnhoekstra commented Jun 5, 2018

Fixes scala/bug#10925

Should fix the test failure on #6559

Added the failing testcase that was generated by scalacheck, and a few close variations.

Make test failure message on the scalacheck tests clearer

@scala-jenkins scala-jenkins added this to the 2.13.0-M5 milestone Jun 5, 2018
val e = format.charAt(noSignificant)
if (e == 'e' || e == 'E') expOK(noSignificant + 1, endIndex)
else false
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Speaking of formatting, no one mentioned the variant space after if. This code base is mostly but not absolutely for the space, which is my preference; but a couple of people omit it. Probably it's best to pick one and gird for battle.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tend to be fully consistent with the rule that I use, like, whatever feels right at the time, man.

But considering I've annoyed you several times in the last week already, and I don't want to stay consistent in that regard, I'll put in some spaces.

Copy link
Contributor

Choose a reason for hiding this comment

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

i.e. (e == 'e' || e == 'E') && expOK(...)

Copy link
Contributor

Choose a reason for hiding this comment

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

I read that we're going for parseDouble compatibility. Just to mention that Scala doesn't take 5.E2 as a constant anymore, because of the ambiguity with selection.

Copy link
Contributor

@som-snytt som-snytt Jun 5, 2018

Choose a reason for hiding this comment

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

And then:

noSignificant != startIndex + 1 && {
  val e = ???
 (e == 'e' || ...) && expOK(...)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@som-snytt This entire validation monster returns a boolean and is mostly made out of expressions that return booleans, so I could make it all in to a vary long series of nested and chained && and || 's. This fragment could be

(startChar == '.' && {
  val noSignificant = skipIndexWhile(ch => ch >= '0' && ch <= '9', startIndex + 1, endIndex)
  (noSignificant != startIndex +1)
} && {
  val e = format.charAt(noSignificant)
  (e == 'e' || e == 'E') && expOP(noSignificant + 1, endIndex)
} || (...)

But the explicit if/elses with boolean literal returns in some places make it much easier to follow for me here. There probably is some arbitrary line where opinions can differ. I have no strong feelings where that line should be, so if there are particular places where you'd like to see it moved, I'm fine with that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, there is a line of taste. Returning true might be a code smell, but I trust your judgment.

val noSignificant = skipIndexWhile(ch => ch >= '0' && ch <= '9', noInt + 1, endIndex)
if(noSignificant >= endIndex) true //no exponent
if (noSignificant >= endIndex) true //no exponent
else {
val e = format.charAt(noSignificant)
(e == 'e' || e == 'E') && expOK(noSignificant + 1, endIndex)
Copy link
Contributor

Choose a reason for hiding this comment

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

Here you didn't if-else it, so I would boost the other expressions, too,

else {
val e = format.charAt(noSignificant)
(e == 'e' || e == 'E') && expOK(noSignificant + 1, endIndex)
}
}
else if(afterIntChar == 'e' || afterIntChar == 'E') expOK(noInt + 1, endIndex)
else if (afterIntChar == 'e' || afterIntChar == 'E') expOK(noInt + 1, endIndex)
else false
Copy link
Contributor

Choose a reason for hiding this comment

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

Like this if-else is exp1 || { val e = ???; exp2 } || exp3.

Copy link
Contributor

@som-snytt som-snytt left a comment

Choose a reason for hiding this comment

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

I think some of the if-else make the code read more imperative than necessary, when a boolean expression suffices, assuming it doesn't become too unwieldy.

It was neat to see scalacheck at work. It's also interesting to read the history of the API upgrade.

Copy link
Contributor

@som-snytt som-snytt left a comment

Choose a reason for hiding this comment

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

Thanks! You may have used extra parens, but who's counting?

@lrytz lrytz merged commit df57e09 into scala:2.13.x Jun 6, 2018
@adriaanm
Copy link
Contributor

adriaanm commented Jun 7, 2018

Could this explain the new test failure we’re seeing in #6635?

@lrytz
Copy link
Member

lrytz commented Jun 7, 2018

Yes, there's already a PR #6746

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.

".E4".toDoubleOption throws NFE
5 participants