[ObjCRuntime] Enable nullability and clean up Blocks.#24726
Conversation
This is file 1 of 7 files with nullability disabled in ObjCRuntime. * Enable nullability (#nullable enable). * Add nullable annotations for block delegate conversion paths and related helper signatures. * Fix number of places where the block API was consumed. * Improve BlockLiteral XML documentation (ordering, spacing, cref usage, and missing member docs). * Fix grammar in docs/api/ObjCRuntime/BlockLiteral.xml. Contributes towards #17285.
There was a problem hiding this comment.
Pull request overview
This pull request enables nullable reference types in src/ObjCRuntime/Blocks.cs and updates all consumers of the BlockLiteral API to handle nullable delegates correctly. This is part 1 of a 7-file effort to enable nullability in the ObjCRuntime namespace.
Changes:
- Enabled
#nullable enablein Blocks.cs and added nullable annotations throughout - Updated
BlockLiteral.GetTarget<T>()to returnT?and added null-safety checks at all call sites - Enhanced XML documentation with better formatting,
<see>references, and an updated code example - Added helper methods
GetTypeName()andGetMethodName()for null-safe error message formatting - Updated the code generator (bgen) to emit null checks for non-void block trampolines
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/ObjCRuntime/Blocks.cs | Enabled nullability, updated API signatures to use nullable types, improved documentation, added helper methods for error messages |
| src/bgen/Generator.cs | Updated trampoline generator to add null checks for non-void return types |
| src/UIKit/UIGuidedAccessRestriction.cs | Replaced direct block access with BlockLiteral.GetTarget() helper |
| src/UIKit/UIConfigurationColorTransformer.cs | Replaced direct block access with BlockLiteral.GetTarget() helper |
| src/UIKit/UICellAccessory.cs | Replaced direct block access with BlockLiteral.GetTarget() helper, added null check |
| src/UIKit/UIAccessibility.cs | Replaced direct block access with BlockLiteral.GetTarget() helper |
| src/Security/SecSharedCredential.cs | Replaced direct block access with BlockLiteral.GetTarget() helper (2 locations) |
| src/MetalPerformanceShaders/MPSImageBatch.cs | Replaced direct block access with BlockLiteral.GetTarget() helper, removed redundant cast |
| src/Metal/MTLDevice.cs | Replaced direct block access with BlockLiteral.GetTarget() helper |
| src/ImageIO/CGImageMetadata.cs | Added null check for delegate retrieved via BlockLiteral.GetTarget() |
| docs/api/ObjCRuntime/BlockLiteral.xml | Removed external XML documentation (now inline in source) |
| tests/cecil-tests/Documentation.KnownFailures.txt | Removed BlockLiteral.Dispose from known failures (now documented) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
✅ [CI Build #9a32ce1] Build passed (Build packages) ✅Pipeline on Agent |
✅ [PR Build #9a32ce1] Build passed (Detect API changes) ✅Pipeline on Agent |
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
✅ [CI Build #9a32ce1] Build passed (Build macOS tests) ✅Pipeline on Agent |
💻 [CI Build #9a32ce1] Tests on macOS X64 - Mac Sonoma (14) passed 💻✅ All tests on macOS X64 - Mac Sonoma (14) passed. Pipeline on Agent |
💻 [CI Build #9a32ce1] Tests on macOS M1 - Mac Monterey (12) passed 💻✅ All tests on macOS M1 - Mac Monterey (12) passed. Pipeline on Agent |
💻 [CI Build #9a32ce1] Tests on macOS arm64 - Mac Sequoia (15) passed 💻✅ All tests on macOS arm64 - Mac Sequoia (15) passed. Pipeline on Agent |
💻 [CI Build #9a32ce1] Tests on macOS M1 - Mac Ventura (13) passed 💻✅ All tests on macOS M1 - Mac Ventura (13) passed. Pipeline on Agent |
💻 [CI Build #9a32ce1] Tests on macOS arm64 - Mac Tahoe (26) passed 💻✅ All tests on macOS arm64 - Mac Tahoe (26) passed. Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
🚀 [CI Build #9a32ce1] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 131 tests passed 🎉 Tests counts✅ cecil: All 1 tests passed. [attempt 2] Html Report (VSDrops) Download Pipeline on Agent |
This is file 1 of 7 files with nullability disabled in ObjCRuntime.
Contributes towards #17285.