Better diagnostics for mixing different nullness pattern matching ways
- Dominant language
- F#
- Stars
- 4.3k
- Forks
- 876
- Avg merge
- 4d 22h
- Merged PRs (30d)
- 144
Description
There are 2 ways to do null-related pattern matching now:
```fsharp
let len1 (str: string | null) =
match str with
| Null -> -1
| NonNull s -> s.Length
let len2 (str: string | null) =
match str with
| null -> -1
| s -> s.Length
```
Both produce no warnings, all good. What I don't like is the behavior when we start mixing those two approaches:
```fsharp
let len3 (str: string | null) =
match str with
| null -> -1
| NonNull s -> s.Length
```
> warning FS3262: Value known to be without null passed to a function meant for nullables: You can remove this |Null|NonNull| pattern usage.
```fsharp
let len4 (str: string | null) =
match str with
| Null -> -1
| s -> s.Length
```
> warning FS3261: Nullness warning: The types 'string' and 'string | null' do not have compatible nullability.
---
As a user I just want consistent diags here in the spirit of "hey, pick one way or another, don't mix things up" - ideally with exact pointers what to change but that's an extra.
I think such errors can happen really often because of fatfingering or copypasting - and casing differences are not even very noticeable, so there is accessibility in the game as well.
_Originally posted by @psfinaki in https://github.com/dotnet/fsharp/pull/15181#discussion_r1677921389_
Contributor guide
Assessment
This issue has not been assessed yet.