[bgen] Propagate nullability information for generic type arguments. Fixes #16860#25541
Conversation
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.
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
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.
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
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.
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
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.
✅ [PR Build #9955220] Build passed (Detect API changes) ✅Pipeline on Agent |
✅ [PR Build #9955220] Build passed (Build packages) ✅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 |
✅ [PR Build #9955220] Build passed (Build macOS tests) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
🚀 [CI Build #9955220] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 199 tests passed 🎉 Tests counts✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
Summary
When properties have generic delegate types (like
Action<NSObject?, NSError?>), bgen now correctly propagates the?nullability annotations on the generic type arguments in the generated C# code.Previously, bgen only read the first byte of the
[NullableAttribute(byte[])]array (for the outer type's nullability), ignoring the remaining bytes that encode nullability for generic type arguments. This caused properties likeAction<UIViewController?, NSError?>to be rendered asAction<UIViewController, NSError>— losing the nullability annotations.Changes
src/bgen/AttributeManager.cs: AddedGetNullabilityBytes()method that extracts the full byte array from[NullableAttribute].src/bgen/TypeManager.cs: AddedFormatType(Type?, Type?, byte[]?)overload and a recursiveFormatTypeUsedInhelper that consumes nullability bytes in depth-first traversal order, correctly skipping value types (which don't have bytes in the array).src/bgen/Generator.cs: Updated property rendering to pass nullability bytes. The "wrap" path applies nullability for all delegate types. The "non-wrap" path only applies for void-returning delegates (Action<>) to avoidFunc<>covariance issues with trampoline signatures.tests/bgen/BGenTests.cs: AddedGenericTypeNullabilitytest with 10 assertions.tests/bgen/tests/generic-type-nullability.cs: Test input covering nullable args, non-nullable args, value types, many args, mixed patterns, and alternating nullability.Key design decisions
NullableAttributearray. The fix correctly identifies value types and skips them during traversal.Func<>covariance guard: Trampolines use non-nullable generic args. This is fine forAction<in T>(contravariant) but breaks forFunc<out T>(covariant). The non-wrap path only applies nullability for void-returning delegates.Fixes #16860
🤖 Pull request created by Copilot