fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

Feature nullness - support overrides of nullness annotation in the imported object hierarchy

Open T-Gro opened this issue 1 year ago • 1 comments

In a nutshell:

Problem 1

Object.ToString() -> string? Boolean.ToString() -> string (no null).

And many others, e.g. StringBuilder, Exception, etc.

This lead to a changed strategy in method resolution, preferring overrides instead of base methods. This however introduced a problem in the case of "partial property override", i.e. an abstract get+set, but override only one of them. Therefore the logic for property equivalence was changed to differentiate the hasgetter/hassetter across properties. And method resolution 'betterness' enhanced to prefer the derived implementation in case of conflicts introduced that way. (otherwise "no unique overload" was being shown if type hieararchy get e.g. get+set | get | set along the way)

Problem 2

Nullness warning was not emited when accessing members of T|null values if those members stemmed from a supertype. E.g. DirectoryInfo.Name was the case. This was implicitely happening because most BCL classes have [Nullable(0)] on them, which was applied on the supertype causing it to be ambivalent.

And our prior algebra for combining nullnesses did not change ambivalent to be WithNull when combined with it.

T-Gro avatar Feb 14 '24 17:02 T-Gro

Can confirm both of these appear to now work:

let aBool = true
let aBoolString = aBool.ToString() // string

let aBoolObj = box aBool
let aBoolObjString = aBoolObj.ToString() // string | null

and

let n : DirectoryInfo | null = DirectoryInfo ""
let o = n.Exists // FS3261

isaacabraham avatar Feb 18 '24 16:02 isaacabraham