Skip to content
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

Closed
inosik opened this issue Oct 3, 2018 · 0 comments
Closed

Invalid binary and octal literals for 64-bit integers are accepted #5729

inosik opened this issue Oct 3, 2018 · 0 comments
Labels
Milestone

Comments

@inosik
Copy link

inosik commented Oct 3, 2018

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.

@cartermp cartermp added this to the 16.0 milestone Oct 17, 2018
@cartermp cartermp modified the milestones: 16.0, 16.1 Feb 21, 2019
gdziadkiewicz added a commit to gdziadkiewicz/fsharp that referenced this issue Mar 21, 2019
@dsyme dsyme mentioned this issue Mar 21, 2019
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
@cartermp cartermp modified the milestones: 16.1, 16.2 Apr 23, 2019
@cartermp cartermp modified the milestones: 16.2, Backlog Apr 30, 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
@cartermp cartermp modified the milestones: Backlog, 16.5 Jan 17, 2020
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
Labels
Projects
None yet
Development

No branches or pull requests

2 participants