Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better diagnostics for nullness inference related errors #17433

Open
psfinaki opened this issue Jul 23, 2024 · 4 comments
Open

Better diagnostics for nullness inference related errors #17433

psfinaki opened this issue Jul 23, 2024 · 4 comments
Labels
Area-Diagnostics mistakes and possible improvements to diagnostics Area-Nullness Issues related to handling of Nullable Reference Types
Milestone

Comments

@psfinaki
Copy link
Member

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)

@github-actions github-actions bot added this to the Backlog milestone Jul 23, 2024
@psfinaki psfinaki added Area-Nullness Issues related to handling of Nullable Reference Types Area-Diagnostics mistakes and possible improvements to diagnostics labels Jul 23, 2024
@vzarytovskii
Copy link
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.

@T-Gro
Copy link
Member

T-Gro commented Jul 31, 2024

Related to: #17409

@T-Gro
Copy link
Member

T-Gro commented Jul 31, 2024

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

@T-Gro
Copy link
Member

T-Gro commented Jul 31, 2024

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
Labels
Area-Diagnostics mistakes and possible improvements to diagnostics Area-Nullness Issues related to handling of Nullable Reference Types
Projects
Status: New
Development

No branches or pull requests

3 participants