diff options
-rw-r--r-- | compiler/semstmts.nim | 2 | ||||
-rw-r--r-- | lib/system/sysstr.nim | 12 | ||||
-rw-r--r-- | tests/enum/tenum.nim | 6 | ||||
-rw-r--r-- | tests/float/tfloat6.nim | 21 | ||||
-rw-r--r-- | tests/float/tfloat7.nim | 26 |
5 files changed, 61 insertions, 6 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index dcc7ecd92..f20a0c36a 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -782,7 +782,7 @@ proc typeSectionFinalPass(c: PContext, n: PNode) = while x.kind in {nkStmtList, nkStmtListExpr} and x.len > 0: x = x.lastSon if x.kind notin {nkObjectTy, nkDistinctTy, nkEnumTy, nkEmpty} and - s.typ.kind notin {tyObject, tyEnum, tyDistinct}: + s.typ.kind notin {tyObject, tyEnum}: # type aliases are hard: var t = semTypeNode(c, x, nil) assert t != nil diff --git a/lib/system/sysstr.nim b/lib/system/sysstr.nim index 3177d05bd..64d6634d2 100644 --- a/lib/system/sysstr.nim +++ b/lib/system/sysstr.nim @@ -328,7 +328,7 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat, fraction: uint64 frac_exponent= 0 exp_sign = 1 - first_digit = 0 + first_digit = -1 has_sign = false # Sign? @@ -359,6 +359,7 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat, # Skip leading zero while s[i] == '0': inc(i) + while s[i] == '_': inc(i) if s[i] in {'0'..'9'}: first_digit = (s[i].ord - '0'.ord) @@ -366,7 +367,7 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat, while s[i] in {'0'..'9'}: inc(kdigits) integer = integer * 10'u64 + (s[i].ord - '0'.ord).uint64 - inc(i); + inc(i) while s[i] == '_': inc(i) # Fractional part? @@ -374,11 +375,12 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat, inc(i) # if no integer part, Skip leading zeros if kdigits <= 0: - while s[i] in {'_','0'}: - inc(i) + while s[i] == '0': inc(frac_exponent) + inc(i) + while s[i] == '_': inc(i) - if s[i] in {'0'..'9'}: + if first_digit == -1 and s[i] in {'0'..'9'}: first_digit = (s[i].ord - '0'.ord) # get fractional part while s[i] in {'0'..'9'}: diff --git a/tests/enum/tenum.nim b/tests/enum/tenum.nim index b081212e6..6d9bdd539 100644 --- a/tests/enum/tenum.nim +++ b/tests/enum/tenum.nim @@ -6,3 +6,9 @@ type var en: E en = a + +# Bug #4066 +import macros +macro genEnum(): untyped = newNimNode(nnkEnumTy).add(newEmptyNode(), newIdentNode("geItem1")) +type GeneratedEnum = genEnum() +doAssert(type(geItem1) is GeneratedEnum) diff --git a/tests/float/tfloat6.nim b/tests/float/tfloat6.nim new file mode 100644 index 000000000..721abd721 --- /dev/null +++ b/tests/float/tfloat6.nim @@ -0,0 +1,21 @@ +discard """ + file: "tfloat6.nim" + output: '''1e-06 : 1e-06 +1e-06 : 1e-06 +0.001 : 0.001 +1e-06 : 1e-06 +1e-06 : 1e-06 +10.000001 : 10.000001 +100.000001 : 100.000001''' +""" + +import strutils + +echo "0.00_0001".parseFloat(), " : ", 1E-6 +echo "0.00__00_01".parseFloat(), " : ", 1E-6 +echo "0.0_01".parseFloat(), " : ", 0.001 +echo "0.00_000_1".parseFloat(), " : ", 1E-6 +echo "0.00000_1".parseFloat(), " : ", 1E-6 + +echo "1_0.00_0001".parseFloat(), " : ", 10.000001 +echo "1__00.00_0001".parseFloat(), " : ", 1_00.000001 diff --git a/tests/float/tfloat7.nim b/tests/float/tfloat7.nim new file mode 100644 index 000000000..2337d1dd4 --- /dev/null +++ b/tests/float/tfloat7.nim @@ -0,0 +1,26 @@ +discard """ + file: "tfloat6.nim" + output: '''passed. +passed. +passed. +passed. +passed. +passed. +passed.''' +""" + +import strutils +template expect_fail(x: expr) = + try: + discard x + echo("expected to fail!") + except ValueError: + echo("passed.") + +expect_fail("1_0._00_0001".parseFloat()) +expect_fail("_1_0_00.0001".parseFloat()) +expect_fail("10.00.01".parseFloat()) +expect_fail("10.00E_01".parseFloat()) +expect_fail("10.00E_01".parseFloat()) +expect_fail("10.00E".parseFloat()) +expect_fail("10.00A".parseFloat()) |