Skip to content

Better diagnostics for nullness inference related errors #17433

Open

Description

@psfinaki

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 #15181 (comment)

Activity

  1. added this to the Backlog milestone on Jul 23, 2024
  2. added
    Area-NullnessIssues related to handling of Nullable Reference Types
    Area-Diagnosticsmistakes and possible improvements to diagnostics
    on Jul 23, 2024
  3. vzarytovskii commented on Jul 23, 2024

    @vzarytovskii
    Member

    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.

  4. T-Gro commented on Jul 31, 2024

    @T-Gro
    Member

    Related to: #17409

  5. T-Gro commented on Jul 31, 2024

    @T-Gro
    Member

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

  6. T-Gro commented on Jul 31, 2024

    @T-Gro
    Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Diagnosticsmistakes and possible improvements to diagnosticsArea-NullnessIssues related to handling of Nullable Reference Types

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions