-
Notifications
You must be signed in to change notification settings - Fork 790
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 - Downcasting should preserve nullness information #17532
Comments
Desribed in https://github.com/fsharp/fslang-design/blob/main/RFCs/FS-1060-nullable-reference-types.md#meaning-of-unbox, perhaps forgotten or ignored for the time being? |
I think there are two perspectives:
This is further complicated by the fslib Unboxing functions doing a runtime lookup, where nullness information is no longer known. A solution which would insist on downcasting a nullable source into a nullable target ( |
A safe but not all-scenarios-covering change would be:
Would that meet the expectations here? |
((null: obj | null) :?> string).Length This shouldn't throw an NRE but should throw an exception during the
No separate warning should be given since now new danger is introduced: If there is a warning it should apply to all uses of |
Feel free to take up that breaking change (which is what a different exception constitutes, I think) with the runtime team (unless you're suggesting F# should start injecting extra null checks before the |
Fixed by #17965 |
Issue description
Downcasting is an operation that returns
null
when input isnull
. However, when the explicit coercion type is not nullable, the downcasting result currently won't be nullable either. Either a nullable type should be required (:?> string | null
) or the downcasting operator should automatically adjust nullness based on the input type.Choose one or more from the following categories of impact
null
constructs in code not using the checknulls switch.null
,not null
).Operating System
Windows (Default)
What .NET runtime/SDK kind are you seeing the issue on
.NET SDK (.NET Core, .NET 5+)
.NET Runtime/SDK version
9.0.0-preview.7.24405.7
Reproducible code snippet and actual behavior
No warning, throws NRE.
Possible workarounds
No response
The text was updated successfully, but these errors were encountered: