Fix SourceGen nullability output for #34130#34193
Conversation
There was a problem hiding this comment.
Pull request overview
Updates MAUI’s XAML SourceGen output to be more nullability-correct, addressing warnings-as-errors scenarios reported in #34130, and adds XAML unit tests to lock the behavior in.
Changes:
- Adjust SourceGen type-conversion code to null-forgive
IExtendedTypeConverterresults before value-type casts to avoid nullable-unboxing warnings. - Update BindingSourceGen type name formatting to preserve nullable reference annotations in generic type arguments while avoiding invalid nullable top-level type syntax.
- Add new
Maui34130Xaml.UnitTests coverage for Runtime and SourceGen inflators.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Controls/tests/Xaml.UnitTests/Issues/Maui34130.xaml.cs | Adds a regression test that validates generated code output for both reported nullability cases. |
| src/Controls/tests/Xaml.UnitTests/Issues/Maui34130.xaml | Provides the XAML scenario that triggers the typed binding and converter paths under test. |
| src/Controls/src/SourceGen/NodeSGExtensions.cs | Adds null-forgiving operator before value-type casts from IExtendedTypeConverter results. |
| src/Controls/src/BindingSourceGen/ITypeSymbolExtensions.cs | Uses a SymbolDisplayFormat that includes nullable reference modifiers and trims top-level ? when needed. |
| // Keep nullable annotations in generic arguments but avoid nullable top-level type syntax (e.g. typeof(Foo?)). | ||
| if (globalName.EndsWith("?")) | ||
| globalName = globalName.Substring(0, globalName.Length - 1); | ||
|
|
There was a problem hiding this comment.
globalName.EndsWith("?") uses the culture-sensitive overload. For consistency with other string comparisons in this repo (and to avoid any culture edge cases), use the overload with StringComparison.Ordinal when checking for the trailing ?.
There was a problem hiding this comment.
Makes sense to add: StringComparison.Ordinal. Just to be safe
There was a problem hiding this comment.
Done — added StringComparison.Ordinal.
9f5fd65 to
2f133bc
Compare
Fixes #34130 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2f133bc to
98506d4
Compare
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
<!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ## Description Fixes two SourceGen nullability issues reported in dotnet#34130: - avoid nullable-unboxing warnings by null-forgiving `IExtendedTypeConverter` results before value-type casts - preserve nullable generic type arguments in BindingSourceGen type names while avoiding invalid nullable top-level type syntax Also adds `Maui34130` Xaml.UnitTest coverage across Runtime and SourceGen inflators. ## Validation - `dotnet build src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj -nologo -v minimal` - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter "FullyQualifiedName~Maui34130" -nologo -v minimal` ## fixes - fixes dotnet#34130 --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
<!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ## Description Fixes two SourceGen nullability issues reported in dotnet#34130: - avoid nullable-unboxing warnings by null-forgiving `IExtendedTypeConverter` results before value-type casts - preserve nullable generic type arguments in BindingSourceGen type names while avoiding invalid nullable top-level type syntax Also adds `Maui34130` Xaml.UnitTest coverage across Runtime and SourceGen inflators. ## Validation - `dotnet build src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj -nologo -v minimal` - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter "FullyQualifiedName~Maui34130" -nologo -v minimal` ## fixes - fixes dotnet#34130 --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Description
Fixes two SourceGen nullability issues reported in #34130:
IExtendedTypeConverterresults before value-type castsAlso adds
Maui34130Xaml.UnitTest coverage across Runtime and SourceGen inflators.Validation
dotnet build src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj -nologo -v minimaldotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter "FullyQualifiedName~Maui34130" -nologo -v minimalfixes