dotnet / dotnet/fsharp

Hex integer literal has unexpected value

Open
#18,041 6 comments 0 reactions 0 assignees View on GitHub
Area-Compiler-Syntax Bug Impact-Low Regression
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

Hex literals that would represent a negative number as a 32-bit value have an unexpected value when bound to a 64-bit value.

**Repro steps**

``` fsharp
let a: int64 = 0xffff_ffff
let b: int64 = 0xffff_ffffL
```

**Expected behavior**

Not sure. It should either:

- fail to compile like in VS 2019
- `a` should be equal to `b`

**Actual behavior**

`a` has a value of -1, as if it was first parsed as a 32-bit signed integer and then converted to a 64-bit integer.

**Known workarounds**

- add the `L` suffix to the literal
- prepend a `0_` to force the value to be parsed as a 64-bit integer (i. e. `0x0_ffff_ffff`)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.