F# diagnostics: create consistent WarningLevel behavior
- Dominant language
- F#
- Stars
- 4.3k
- Forks
- 876
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 131
Description
I propose to fix F# diagnostics so that the WarningLevel option does what the compiler reference says (see below) and thus aligns with the C# concept of `WarningLevel`
Every C# diagnostic CSxxxx has a well-defined warning level.
Errors have level 0, warnings have level 1 to 3 and informational warnings have level 4.
When building with `n` or `--warn:n`, all diagnostics up to level `n` are shown.
For F#, the [compiler reference](https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/compiler-options) says
> `--warn:warning-level`
Sets a warning level (0 to 5). The default level is 3. Each warning is given a level based on its severity. Level 5 gives more, but less severe, warnings than level 1.
This compiler option is equivalent to the C# compiler option of the same name. For more information, see /warn (C# Compiler Options).
However, the levels are not documented (except for the opt-in warnings).
Playing with the warning level (or diving deep into the compiler), you find
- Level 0: errors
- Level 1: info (informational warnings)
- Level 2: non-opt-in warnings
- Level 5: "opt-in" warnings 21, 22, 52, 1178
- No level (never shown): the remaining "opt-in" warnings
I propose to change this to
- Level 0: errors
- Level 2: warnings
- Level 3: info
- Level 5: opt-in warnings 21, 22, 52, 1178
- Level 6: the remaining opt-in warnings
While 4 for Info would be closer to C#, the above choice is for backwards compatibility.
Also for compatibility reasons, the proposal uses level 5 and 6 for opt-in warnings. (Note that C# uses levels above 4 for "warnings waves", which, I believe, we don't need. EDIT: see discussion below.)
All the nowarn/warnon/warnaserror functionality will of course continue to be supported.
The WarningLevel filter should work both for fsc and for editor support.
## Pros and Cons
The new warning levels are more consistent, are extensible and can more easily be documented.
They align with the SDK and C# concept of "Warning level".
They will simplify the compiler code and make it more maintainable. (That's actually why I bring it up ;-))
**Compatibility issues:**
For WarningLevel 2 and lower, info warnings are no longer shown in the editor.
For WarningLevel 3 and above, fsc will print the info warnings.
For WarningLevel 6 and higher, opt-in warnings may appear that were not shown previously.
(I found on github two repositories with .fsproj files with WarningLevel 2; zero with WarningLevel 6, out of a total of 10k .fsproj with explicit WarningLevel.)
Contributor guide
Assessment
This issue has not been assessed yet.