Skip to content

Commit

Permalink
update test; change function calling condition
Browse files Browse the repository at this point in the history
  • Loading branch information
ijklam committed May 24, 2024
1 parent 9f739ca commit 171914e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7612,10 +7612,12 @@ and TcConstExpr cenv (overallTy: OverallTy) env m tpenv c =
let res = Regex.Match(s, @"^-?0*(?<number>\d+\.?\d*?)0*(?:$|[eE][+-]?(?<exp>\d+))")
let exp = res.Groups.["exp"]
let number = res.Groups.["number"]
let isNumberContainsDot = -1 <> number.Value.IndexOf '.'
let maxLen = if isNumberContainsDot then 16 else 15

if not res.Success || (-1 = number.Value.IndexOf '.' && not exp.Success) then
if not res.Success || (not isNumberContainsDot && not exp.Success) then
mkFunctionCall ("FromString", SynConst.String (s, SynStringKind.Regular, m))
elif (not exp.Success || int exp.Value <= 300) && number.Length <= 15 then
elif (not exp.Success || int exp.Value <= 300) && number.Length <= maxLen then
let f64 = float s
mkFunctionCall ("FromFloat", SynConst.Double f64)
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module ``Numeric Literals`` =
|> typecheck
|> shouldFail
|> withSingleDiagnostic (Error 1156, Line 1, Col 9, Line 1, Col (9 + (String.length literal)),
"This is not a valid numeric literal. Valid numeric literals include 1, 0x1, 0o1, 0b1, 1l (int/int32), 1u (uint/uint32), 1L (int64), 1UL (uint64), 1s (int16), 1us (uint16), 1y (int8/sbyte), 1uy (uint8/byte), 1.0 (float/double), 1.0f (float32/single), 1.0m (decimal), 1n (nativeint), 1un (unativeint), 1I (bigint), .")
"This is not a valid numeric literal. Valid numeric literals include 1, 0x1, 0o1, 0b1, 1l (int/int32), 1u (uint/uint32), 1L (int64), 1UL (uint64), 1s (int16), 1us (uint16), 1y (int8/sbyte), 1uy (uint8/byte), 1.0 (float/double), 1.0f (float32/single), 1.0m (decimal), 1n (nativeint), 1un (unativeint), 1I (bigint).")

[<Theory>]
[<InlineData("0xABCI")>]
Expand Down

0 comments on commit 171914e

Please sign in to comment.