CheckForOverflowUnderflow property does not enable overflow checking, as the documentation implies
- Dominant language
- F#
- Stars
- 4.3k
- Forks
- 876
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 131
Description
**Repro steps**
Create and run a simple project like this:
```
Exe
net5.0
true
```
Program.fs
```
[]
let main argv =
printfn "%d" (System.Int32.MaxValue + 1)
0
```
**Expected behavior**
OverflowException is thrown, because overflow checking was enabled by CheckForOverflowUnderflow=true. The [compiler options documentation](https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/compiler-options) says
> --checked[+\|-] | Enables or disables the generation of overflow checks. This compiler option is equivalent to the C# compiler option of the same name. For more information, see [/checked (C# Compiler Options)](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/language#checkforoverflowunderflow).
and the linked C# compiler options page says
> The CheckForOverflowUnderflow option specifies whether an integer arithmetic statement that results in a value that is outside the range of the data type causes a run-time exception.
> `true`
This led me to believe that `true` would also work for F#.
**Actual behavior**
-2147483648 is printed, because overflow checking is actually not enabled.
**Known workarounds**
Add this to the project instead:
`--checked+`
**Related information**
At minimum the documentation should be clarified, but it would be much better to make the CheckForOverflowUnderflow property work, of course.
F# Compiler version 11.0.0.0 for F# 5.0
* Operating system: Windows 7 x64
* .NET Runtime kind: .NET 5.0.4
* Editing Tools: VS 2019, Rider
Contributor guide
Assessment
This issue has not been assessed yet.