[mtouch/dotnet-linker] Enable nullability in most files and fix any issues.#24565
[mtouch/dotnet-linker] Enable nullability in most files and fix any issues.#24565rolfbjarne merged 4 commits intomainfrom
Conversation
…ssues. Also delete a little bit of dead code in the process. This was mostly done by Copilot, which summarizes its work like this (which may not be entirely accurate, because some of Copilot's changes were slightly modified): --- Fix nullability warnings/errors in files used by the dotnet-linker project, excluding Registrar.cs and StaticRegistrar.cs which require more extensive refactoring. Changes: - Make fields nullable where they may not be initialized (Cache, DlsymAssemblies, CustomLinkFlags, DeploymentTarget, SdkVersion, etc.) - Add null checks before dereferencing nullable fields - Make method parameters nullable where null is a valid argument - Use var for variable declarations where type is obvious - Use null-coalescing operators for safe string formatting - Add guard clauses with meaningful exceptions for required nullable fields Files modified: - Application.cs: Made many fields nullable, added null checks for nullable value types, added exception throws for unset required values - Assembly.cs: Added null checks for Cache and DeploymentTarget - Driver.cs: Fixed null dereference for NativeSdkVersion - Driver.execution.cs: Made Dictionary and Action parameters nullable - ErrorHelper.tools.cs: Made fields and method parameters nullable - Frameworks.cs: Made static framework collections nullable - Target.cs: Made LinkContext and framework lookup nullable - TargetFramework.cs: Made identifier/version/profile nullable, fixed Equals - LinkerConfiguration.cs: Added null check for Cache - ManagedRegistrarStep.cs: Added null checks for property accessor - PreserveSmartEnumConversions.cs: Fixed null arg with coalescing Registrar.cs and StaticRegistrar.cs are excluded from this change as they contain deeply interconnected internal classes where making fields nullable causes cascading effects requiring comprehensive refactoring.
There was a problem hiding this comment.
Pull request overview
Enables C# nullable reference types across mtouch/dotnet-linker/linker-related code and applies targeted nullability fixes (plus a few small refactors/dead-code removals) to satisfy nullable warnings-as-errors.
Changes:
- Enable nullable reference types at the project level and in many individual source files (
#nullable enable). - Update field/parameter nullability and add null checks/guards to resolve NRT warnings.
- Minor refactors while touching code (e.g.,
out var, null-coalescing in messages, some logic cleanup).
Reviewed changes
Copilot reviewed 37 out of 37 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/mtouch/mtouch.csproj | Enables nullable reference types for mtouch. |
| tools/mtouch/DotNetGlobals.cs | Adds global System.Diagnostics.CodeAnalysis using for nullable attributes. |
| tools/mtouch/AssemblyResolver.cs | Enables NRT and adjusts resolver return nullability and directory checks. |
| tools/linker/RegistrarRemovalTrackingStep.cs | Enables NRT and tightens Resolve() handling to avoid null deref. |
| tools/linker/ObjCExtensions.cs | Makes extension methods tolerate null inputs and adds defensive checks. |
| tools/linker/MonoTouch.Tuner/ProcessExportedFields.cs | Enables NRT and updates symbol extraction to return nullable. |
| tools/linker/MonoTouch.Tuner/PreserveSmartEnumConversions.cs | Enables NRT, makes cache nullable, and improves warning formatting. |
| tools/linker/MonoTouch.Tuner/ListExportedSymbols.cs | Enables NRT, makes generator state nullable, and adds null guards around registrar usage. |
| tools/linker/MobileExtensions.cs | Enables NRT and annotates/guards custom attribute helpers. |
| tools/linker/MarkNSObjects.cs | Enables NRT and makes product assembly tracking nullable. |
| tools/linker/CoreTypeMapStep.cs | Enables NRT and makes cached dictionaries nullable/lazy-initialized. |
| tools/linker/CoreOptimizeGeneratedCode.cs | Enables NRT and adds null guards in instruction processing. |
| tools/dotnet-linker/dotnet-linker.csproj | Enables nullable reference types for dotnet-linker. |
| tools/dotnet-linker/Steps/ManagedRegistrarStep.cs | Adjusts UnmanagedCallersOnly EntryPoint handling (and related comments). |
| tools/dotnet-linker/LinkerConfiguration.cs | Adds null check around Application.Cache before setting Location. |
| tools/dotnet-linker/DotNetGlobals.cs | Adds global System.Diagnostics.CodeAnalysis using for nullable attributes. |
| tools/dotnet-linker/AppBundleRewriter.cs | Adds nullability annotation for out param via [NotNullWhen(true)]. |
| tools/common/cache.cs | Enables NRT and makes cache directory backing field nullable. |
| tools/common/TargetFramework.cs | Enables NRT and updates parsing locals/Equals signature. |
| tools/common/Target.cs | Enables NRT and makes link context access nullable-aware. |
| tools/common/Symbols.cs | Enables NRT and updates symbol name/objective-c-name nullability. |
| tools/common/PInvokeWrapperGenerator.cs | Enables NRT and converts key fields into required properties. |
| tools/common/Optimizations.cs | Enables NRT and refactors nullable bool handling in initialization/ToString. |
| tools/common/NullableAttributes.cs | Extends compatibility nullable attributes with MemberNotNullAttribute. |
| tools/common/Frameworks.cs | Enables NRT and makes framework collections/lazy singletons nullable-aware. |
| tools/common/ErrorHelper.tools.cs | Enables NRT and updates signatures/locals for nullable flow. |
| tools/common/Driver.execution.cs | Enables NRT and updates RunCommand overloads/env typing and callback handling. |
| tools/common/Driver.cs | Enables NRT and updates various fields/properties and directory creation logic. |
| tools/common/DerivedLinkContext.cs | Enables NRT and updates annotations/attribute storage typing. |
| tools/common/CoreResolver.cs | Enables NRT and makes directories nullable plus nullable-aware assembly loading. |
| tools/common/CompilerFlags.cs | Enables NRT and makes internal collections nullable-aware. |
| tools/common/Assembly.cs | Enables NRT and adds/updates nullable annotations and extraction guards. |
| tools/common/Application.cs | Enables NRT and updates many fields/properties to be nullable/guarded. |
| builds/mono-ios-sdk-destdir/ios-sources/external/linker/src/tuner/Mono.Tuner/Extensions.cs | Enables NRT and updates assembly retrieval APIs to nullable-aware patterns. |
| builds/mono-ios-sdk-destdir/ios-sources/external/linker/src/tuner/Mono.Tuner/CecilRocks.cs | Enables NRT and updates helpers to return nullable where appropriate. |
| builds/mono-ios-sdk-destdir/ios-sources/external/linker/src/linker/Linker/TypeReferenceExtensions.cs | Enables NRT and updates return type nullability and guards. |
| builds/mono-ios-sdk-destdir/ios-sources/external/linker/src/linker/Linker/MethodDefinitionExtensions.cs | Enables NRT and updates event/property lookup helpers to nullable returns. |
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 #0bfee7a] Build passed (Detect API changes) ✅Pipeline on Agent |
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.
✅ 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 |
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.
✅ [CI Build #0bfee7a] Build passed (Build packages) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ [CI Build #0bfee7a] Build passed (Build macOS tests) ✅Pipeline on Agent |
💻 [CI Build #0bfee7a] Tests on macOS X64 - Mac Sonoma (14) passed 💻✅ All tests on macOS X64 - Mac Sonoma (14) passed. Pipeline on Agent |
💻 [CI Build #0bfee7a] Tests on macOS M1 - Mac Monterey (12) passed 💻✅ All tests on macOS M1 - Mac Monterey (12) passed. Pipeline on Agent |
💻 [CI Build #0bfee7a] Tests on macOS M1 - Mac Ventura (13) passed 💻✅ All tests on macOS M1 - Mac Ventura (13) passed. Pipeline on Agent |
💻 [CI Build #0bfee7a] Tests on macOS arm64 - Mac Sequoia (15) passed 💻✅ All tests on macOS arm64 - Mac Sequoia (15) passed. Pipeline on Agent |
💻 [CI Build #0bfee7a] 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 #0bfee7a] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 117 tests passed 🎉 Tests counts✅ cecil: All 1 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
Also delete a little bit of dead code in the process.
This was mostly done by Copilot, which summarizes its work like this (which
may not be entirely accurate, because some of Copilot's changes were slightly
modified):
Fix nullability warnings/errors in files used by the dotnet-linker project,
excluding Registrar.cs and StaticRegistrar.cs which require more extensive
refactoring.
Changes:
CustomLinkFlags, DeploymentTarget, SdkVersion, etc.)
Files modified:
value types, added exception throws for unset required values
Registrar.cs and StaticRegistrar.cs are excluded from this change as they
contain deeply interconnected internal classes where making fields nullable
causes cascading effects requiring comprehensive refactoring.