Skip to content

Commit 2fec08b

Browse files
authored
Merge pull request scala#5717 from som-snytt/issue/10148-followup
SI-10148 Accept verbose zero
2 parents 147e5dd + f3d271b commit 2fec08b

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/compiler/scala/tools/nsc/ast/parser/Scanners.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -983,15 +983,16 @@ trait Scanners extends ScannersCommon {
983983

984984
def intVal: Long = intVal(negated = false)
985985

986+
private val zeroFloat = raw"[0.]+(?:[eE][+-]?[0-9]+)?[fFdD]?".r
987+
986988
/** Convert current strVal, base to float value.
987989
*/
988990
def floatVal(negated: Boolean): Float = {
989991
try {
990992
val value: Float = java.lang.Float.parseFloat(strVal)
991993
if (value > Float.MaxValue)
992994
syntaxError("floating point number too large")
993-
val zeroly = "0.fF"
994-
if (value == 0.0f && strVal.exists(c => !zeroly.contains(c)))
995+
if (value == 0.0f && !zeroFloat.pattern.matcher(strVal).matches)
995996
syntaxError("floating point number too small")
996997
if (negated) -value else value
997998
} catch {
@@ -1010,8 +1011,7 @@ trait Scanners extends ScannersCommon {
10101011
val value: Double = java.lang.Double.parseDouble(strVal)
10111012
if (value > Double.MaxValue)
10121013
syntaxError("double precision floating point number too large")
1013-
val zeroly = "0.dD"
1014-
if (value == 0.0d && strVal.exists(c => !zeroly.contains(c)))
1014+
if (value == 0.0d && !zeroFloat.pattern.matcher(strVal).matches)
10151015
syntaxError("double precision floating point number too small")
10161016
if (negated) -value else value
10171017
} catch {

test/files/run/literals.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
object Test {
88

9-
/* I add a couple of Unicode identifier tests here temporarily */
9+
/* I add a couple of Unicode identifier tests here "temporarily" */
1010

1111
def \u03b1\u03c1\u03b5\u03c4\u03b7 = "alpha rho epsilon tau eta"
1212

@@ -80,6 +80,9 @@ object Test {
8080
check_success("1e1f == 10.0f", 1e1f, 10.0f)
8181
check_success(".3f == 0.3f", .3f, 0.3f)
8282
check_success("0f == 0.0f", 0f, 0.0f)
83+
check_success("0f == -0.000000000000000000e+00f", 0f, -0.000000000000000000e+00f)
84+
check_success("0f == -0.000000000000000000e+00F", 0f, -0.000000000000000000e+00F)
85+
check_success("0f == -0.0000000000000000e14f", 0f, -0.0000000000000000e14f)
8386
check_success("01.23f == 1.23f", 01.23f, 1.23f)
8487
check_success("3.14f == 3.14f", 3.14f, 3.14f)
8588
check_success("6.022e23f == 6.022e23f", 6.022e23f, 6.022e23f)
@@ -96,6 +99,11 @@ object Test {
9699
check_success(".3 == 0.3", .3, 0.3)
97100
check_success("0.0 == 0.0", 0.0, 0.0)
98101
check_success("0d == 0.0", 0d, 0.0)
102+
check_success("0d == 0.000000000000000000e+00d", 0d, 0.000000000000000000e+00d)
103+
check_success("0d == -0.000000000000000000e+00d", 0d, -0.000000000000000000e+00d)
104+
check_success("0d == -0.000000000000000000e+00D", 0d, -0.000000000000000000e+00D)
105+
check_success("0.0 == 0.000000000000000000e+00", 0.0, 0.000000000000000000e+00)
106+
check_success("0.0 == -0.000000000000000000e+00", 0.0, -0.000000000000000000e+00)
99107
check_success("01.23 == 1.23", 01.23, 1.23)
100108
check_success("01.23d == 1.23d", 01.23d, 1.23d)
101109
check_success("3.14 == 3.14", 3.14, 3.14)

0 commit comments

Comments
 (0)