Skip to content

Fix SourceGen nullability output for #34130#34193

Merged
StephaneDelcroix merged 3 commits intomainfrom
dev/stdelc/issue34130-xaml-repro
Feb 25, 2026
Merged

Fix SourceGen nullability output for #34130#34193
StephaneDelcroix merged 3 commits intomainfrom
dev/stdelc/issue34130-xaml-repro

Conversation

@StephaneDelcroix
Copy link
Copy Markdown
Contributor

@StephaneDelcroix StephaneDelcroix commented Feb 23, 2026

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:

  • 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

Copilot AI review requested due to automatic review settings February 23, 2026 15:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 IExtendedTypeConverter results 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 Maui34130 Xaml.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.

Comment on lines +52 to +55
// 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);

Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to add: StringComparison.Ordinal. Just to be safe

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — added StringComparison.Ordinal.

StephaneDelcroix and others added 2 commits February 25, 2026 11:20
Fixes #34130

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@StephaneDelcroix StephaneDelcroix force-pushed the dev/stdelc/issue34130-xaml-repro branch from 2f133bc to 98506d4 Compare February 25, 2026 10:21
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@StephaneDelcroix StephaneDelcroix merged commit 420846b into main Feb 25, 2026
28 checks passed
@StephaneDelcroix StephaneDelcroix deleted the dev/stdelc/issue34130-xaml-repro branch February 25, 2026 18:48
jfversluis pushed a commit to yuriikyry4enko/maui that referenced this pull request Feb 26, 2026
<!-- 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>
TamilarasanSF4853 pushed a commit to TamilarasanSF4853/maui that referenced this pull request Mar 2, 2026
<!-- 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>
@github-actions github-actions bot locked and limited conversation to collaborators Mar 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Xaml Source Generator generates nullable warnings, we have warnings as errors.

3 participants