-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix 10156: Put generic number literals under a flag #10286
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
Conversation
Don't forget to mention this flag is required in https://dotty.epfl.ch/docs/reference/changed-features/numeric-literals.html |
We should add a import scala.util.FromDigits
object Test extends App {
val x: BigInt = 13232202002020202020202 // error
val z: BigDecimal = 132322020020.223 // error
case class Even(n: Int)
given FromDigits[Even] {
def fromDigits(digits: String): Even = {
val intValue = digits.toInt
if (intValue % 2 == 0) Even(intValue)
else throw FromDigits.MalformedNumber()
}
}
val e: Even = 1234 // error
try {
println(123: Even) // error
} catch {
case ex: FromDigits.MalformedNumber => println("malformed")
}
x match {
case 13_232_202_002_020_202_020_202 => () // error
}
(x: Any) match {
case 13232202002020202020202: BigInt => () // error
}
x match {
case 13232202002020202020202 => assert(false) // error
case -0xaabb12345ACF12345AC => () // error
}
(e: Any) match {
case 1234: Even => // error
case _: Even => // error
}
} |
should there be a follow up to move the |
I had a look at it, but then decided that the downsides would be too high.
So, moving it elsewhere would cause a lot of breakage, for no apparent gain. The functionality to convert a digit string into some given type is useful. Also it's not like generic number literals have been rejected. They have been deferred since they are non-essential for 3.0. I suspect they'll make a comeback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
Actually, under a language import