-
Notifications
You must be signed in to change notification settings - Fork 784
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
Nullness issue - Option<string> is marked as NotNull using NullabilityInfoContext #17517
Comments
Thanks for reporting this. It is safe to consider them not-null in F# understanding, but for C# consumers, they must be reported as nullable via IL metadata. |
Note: This is part of the unresolved question in the RFC https://github.com/fsharp/fslang-design/blob/main/RFCs/FS-1060-nullable-reference-types.md#interaction-with-usenullastruevalue |
At least for C# consumers (or NullabilityInfoContext for serializers, schema generators etc.) it must indicate that runtime value of The usage within F# (or rather, what can be improved without breaking much of existing code) is harder, I agree. |
@T-Gro Would it be possible to consider |
Yes I've seen the problem with my own deserializer. I don't want to deal specifically building a given type (here option<>.None - if null is ok for a type instance, there is no problem. And null here is a perfectly valid value).
There are so many attributes on f# types I would be surprised something can't be sorted out. Between UseNullAsTrueValue and AllowNullLiteral there is a semantic distinction. Outside F# (and I include deserializers), probably we do not care. It's nullable and it's ok - it's expected to work correctly as before for UseNullAsTrueValue. Within F#, it's not matchable with null (despite being null, for eg Option.None for RT). And this shall be ok too - and for me this shall rely on AllowNullLiteral only). Maybe I do not understand the whole story tho 🙂 |
Unlikely. |
I think you are right here. |
And |
Issue description
Looks like
Option<string>
in marked as NotNull when usingNullabilityInfoContext
. I expect it to be reported asNullable
sinceOption<string>
fornull
has anull
representation (UseNullAsTrueValue
).With provided snippet, I expect
StringOption
to be reported asNullable
, notNotNull
.Choose one or more from the following categories of impact
null
constructs in code not using the checknulls switch.null
,not null
).Operating System
macOS
What .NET runtime/SDK kind are you seeing the issue on
.NET SDK (.NET Core, .NET 5+)
.NET Runtime/SDK version
9.0.100-preview.6.24328.19
Reproducible code snippet and actual behavior
Possible workarounds
No response
The text was updated successfully, but these errors were encountered: