When using binary or octal literals for 64-bit integers (both signed and unsigned) the compiler doesn't check for overflows and accepts more than 64 bits.
This also applies to LanguagePrimitives.ParseInt64 and LanguagePrimitives.ParseUInt64.
I noticed that after I ported that portion of the code from the F# compiler to an app of mine.
This is the code in the compiler:
https://github.com/Microsoft/visualfsharp/blob/fead0aac540485683f694524eadad79983ec28d9/src/fsharp/lex.fsl#L69-L75
This is the code in FSharp.Core:
https://github.com/Microsoft/visualfsharp/blob/92247b886e4c3f8e637948de84b6d10f97b2b894/src/fsharp/FSharp.Core/prim-types.fs#L2363-L2369
Repro steps
let N = 0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1L
// Actually 65 bits
// ---------------------------------------------------------------------------------------^
I prepared a repro project here: repro.zip
Expected behavior
The compiler should emit FS1149 and FS1150 for signed and unsigned long integers, respectively. The ParseInt64 and ParseUInt64 functions should fail with an OverflowException.
Actual behavior
The compiler accepts more than 64 bits in binary and octal literals. The numbers end up being equal to -1 for int64 and UInt64.MaxValue for uint64.
Known workarounds
Use decimal or hexadecimal literals.
Related information
I can reproduce that on Windows 10 with VS 2017 and on macOS with the .NET Core SDK 2.1.402.
When using binary or octal literals for 64-bit integers (both signed and unsigned) the compiler doesn't check for overflows and accepts more than 64 bits.
This also applies to
LanguagePrimitives.ParseInt64andLanguagePrimitives.ParseUInt64.I noticed that after I ported that portion of the code from the F# compiler to an app of mine.
This is the code in the compiler:
https://github.com/Microsoft/visualfsharp/blob/fead0aac540485683f694524eadad79983ec28d9/src/fsharp/lex.fsl#L69-L75
This is the code in FSharp.Core:
https://github.com/Microsoft/visualfsharp/blob/92247b886e4c3f8e637948de84b6d10f97b2b894/src/fsharp/FSharp.Core/prim-types.fs#L2363-L2369
Repro steps
I prepared a repro project here: repro.zip
Expected behavior
The compiler should emit
FS1149andFS1150for signed and unsigned long integers, respectively. TheParseInt64andParseUInt64functions should fail with anOverflowException.Actual behavior
The compiler accepts more than 64 bits in binary and octal literals. The numbers end up being equal to
-1forint64andUInt64.MaxValueforuint64.Known workarounds
Use decimal or hexadecimal literals.
Related information
I can reproduce that on Windows 10 with VS 2017 and on macOS with the .NET Core SDK 2.1.402.