-
Notifications
You must be signed in to change notification settings - Fork 790
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
Invalid binary and octal literals for 64-bit integers are accepted #5729
Comments
gdziadkiewicz
added a commit
to gdziadkiewicz/fsharp
that referenced
this issue
Mar 21, 2019
Merged
gdziadkiewicz
added a commit
to gdziadkiewicz/fsharp
that referenced
this issue
Mar 21, 2019
gdziadkiewicz
added a commit
to gdziadkiewicz/fsharp
that referenced
this issue
Apr 2, 2019
gdziadkiewicz
added a commit
to gdziadkiewicz/fsharp
that referenced
this issue
Jun 15, 2019
gdziadkiewicz
added a commit
to gdziadkiewicz/fsharp
that referenced
this issue
Jun 15, 2019
gdziadkiewicz
added a commit
to gdziadkiewicz/fsharp
that referenced
this issue
Jul 17, 2019
gdziadkiewicz
added a commit
to gdziadkiewicz/fsharp
that referenced
this issue
Aug 16, 2019
gdziadkiewicz
added a commit
to gdziadkiewicz/fsharp
that referenced
this issue
Aug 21, 2019
nosami
pushed a commit
to xamarin/visualfsharp
that referenced
this issue
Feb 23, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
andLanguagePrimitives.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
FS1149
andFS1150
for signed and unsigned long integers, respectively. TheParseInt64
andParseUInt64
functions 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
-1
forint64
andUInt64.MaxValue
foruint64
.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.
The text was updated successfully, but these errors were encountered: