Skip to content

Add Unchecked.withNull for unconstrained C# nullable-generic interop - #20232

Open
T-Gro wants to merge 2 commits into
mainfrom
t-gro-unchecked-with-null-interop
Open

Add Unchecked.withNull for unconstrained C# nullable-generic interop#20232
T-Gro wants to merge 2 commits into
mainfrom
t-gro-unchecked-with-null-interop

Conversation

@T-Gro

@T-Gro T-Gro commented Aug 7, 2026

Copy link
Copy Markdown
Member

Relates to #17734.

Adds Unchecked.withNull : 'T -> 'T | null, an escape hatch for implementing and consuming unconstrained C# nullable-generic APIs (T? M<T>(), interface { T? GetValue<T>(int) }). Unlike Operators.withNull it places no not null/not struct constraint on 'T, so such a slot can be satisfied without FS3261.

It is inline and erases to a retype ((# "" value : 'T | null #)) — nothing lands in IL. Documented as unsafe/interop-only: 'T | null is meaningless for a struct 'T. Assigning null to a resulting mutable at a struct lowers to default(T) (ILVerify-clean through multiple generic layers); the same on a concrete struct mutable stays a compile error (FS0043).

Adds an inline escape hatch re-typing 'T to 'T | null with no not null /
not struct constraint, so unconstrained C# nullable-generic APIs
(T? M<T>()) can be implemented and consumed from F#.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: acdc940e-b98f-4072-b143-a3e296e12fcb
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

❗ Release notes required

You can open this PR in browser to add release notes: open in github.dev


✅ Found changes and release notes in following paths:

Change path Release notes path Description
`src/FSharp.Core` docs/release-notes/.FSharp.Core/11.0.100.md

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: acdc940e-b98f-4072-b143-a3e296e12fcb
@github-actions github-actions Bot added the AI-Tooling-Check-Bypassed Tooling check: non-fork PR, not diff-analyzed label Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-Tooling-Check-Bypassed Tooling check: non-fork PR, not diff-analyzed

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

1 participant