fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

Better diagnostics for nullness inference related errors

Open psfinaki opened this issue 1 year ago • 4 comments

I think it would be good to be more explicit about nullness inference happening behind the scenes.

For the code

let xs = [| ""; ""; null |]

we'll get

Nullness warning: The type 'string' does not support 'null'

It would be helpful to have something like

"xs was inferred to have the type string[] but got null among its values. Either explicitly specify null in the return type ((string | null)[]), or remove null from the collection - or suppress the warning but no please don't."

Originally posted by @psfinaki in https://github.com/dotnet/fsharp/pull/15181#discussion_r1679527189

psfinaki avatar Jul 23 '24 11:07 psfinaki

We don't differentiate between collections and other types. string and string array are no different for us. This would probably be better solved in analyzers, rather than typechecker.

vzarytovskii avatar Jul 23 '24 11:07 vzarytovskii

Related to: https://github.com/dotnet/fsharp/issues/17409

T-Gro avatar Jul 31 '24 17:07 T-Gro

Option: Specialize type unification for list/array/sequence builders.

T-Gro avatar Jul 31 '24 17:07 T-Gro

Diagnostics can offer: Explicit annotation or "be first" rule.

T-Gro avatar Jul 31 '24 17:07 T-Gro