Skip to content

[XC] better support for nullable props and BPs #28550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2025

Conversation

StephaneDelcroix
Copy link
Contributor

@StephaneDelcroix StephaneDelcroix commented Mar 21, 2025

Description of Change

As requested by @jfversluis: support nullable BPs and props

Issues Fixed

Fixes #28010

@Copilot Copilot AI review requested due to automatic review settings March 21, 2025 11:28
@StephaneDelcroix StephaneDelcroix requested a review from a team as a code owner March 21, 2025 11:28
Copy link
Contributor

@Copilot 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

This pull request improves support for nullable bindable properties and properties by updating how values are set and unboxed in the IL generation logic. Key changes include:

  • Introducing a new local function CanSetValue in SetPropertiesVisitor.cs to encapsulate value setting logic.
  • Adjusting the handling of nullable types in the SetValue and CanSetValue routines.
  • Updating test cases in Unreported008.xaml.cs and Bz24910.xaml.cs to verify proper handling of nullable types and replacing hard-coded property names with nameof().

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.

File Description
src/Controls/src/Build.Tasks/SetPropertiesVisitor.cs Refactors value setting logic with a new local helper and adjusts nullable type handling
src/Controls/tests/Xaml.UnitTests/Issues/Unreported008.xaml.cs Adds a new view to test nullable bindable property behavior
src/Controls/tests/Xaml.UnitTests/Issues/Bz24910.xaml.cs Updates BindableProperty.Create calls to use nameof(), ensuring consistency
src/Controls/src/Build.Tasks/VariableDefinitionExtensions.cs Comments out a branch for unboxing nullable types, likely for future reconsideration
Files not reviewed (1)
  • src/Controls/tests/Xaml.UnitTests/Issues/Unreported008.xaml: Language not supported
Comments suppressed due to low confidence (2)

src/Controls/src/Build.Tasks/SetPropertiesVisitor.cs:1459

  • The original code returned the result of an inheritance check for the variable type against bpTypeRef, whereas the new code unconditionally returns false. This change might inadvertently break scenarios where the variable type inherits from bpTypeRef; please verify that the new behavior is intentional.
return false;

src/Controls/src/Build.Tasks/VariableDefinitionExtensions.cs:21

  • There is an unused commented code block related to handling System.Nullable`1 types. Consider removing it or adding a clarifying comment if it’s intended to indicate future work to avoid confusion.
//  yield return Instruction.Create(OpCodes.Unbox_Any, module.ImportReference(type));

yield return instruction;
if (bpTypeRef.IsValueType)
{
if ( bpTypeRef.ResolveCached(context.Cache).FullName == "System.Nullable`1"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the main change

@StephaneDelcroix StephaneDelcroix force-pushed the fix_nullableValueTypeBP branch from 792bb9d to bbd5372 Compare March 21, 2025 11:31
@@ -1410,6 +1410,25 @@ static IEnumerable<Instruction> SetBinding(VariableDefinition parent, FieldRefer

static bool CanSetValue(FieldReference bpRef, bool attached, INode node, IXmlLineInfo iXmlLineInfo, ILContext context)
{
static bool CanSetValue (TypeReference bpTypeRef, VariableDefinition varValue, ILContext context, IXmlLineInfo iXmlLineInfo)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

extracting the logic in a local method to run it twice, once on the nullable type, once on the inner type

@jfversluis jfversluis added this to the .NET 9 SR6 milestone Mar 21, 2025
@jfversluis jfversluis moved this to Approved in MAUI SDK Ongoing Mar 21, 2025
@PureWeen PureWeen changed the base branch from main to inflight/current March 23, 2025 23:54
@PureWeen PureWeen modified the milestones: .NET 9 SR6, .NET 9 SR7 Mar 23, 2025
@PureWeen PureWeen merged commit eb8e9ad into inflight/current Mar 23, 2025
125 of 129 checks passed
@PureWeen PureWeen deleted the fix_nullableValueTypeBP branch March 23, 2025 23:55
@github-project-automation github-project-automation bot moved this from Approved to Done in MAUI SDK Ongoing Mar 23, 2025
bhavanesh2001 pushed a commit to bhavanesh2001/maui that referenced this pull request Apr 11, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Apr 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

XAML inflator fail setting nullable value types
3 participants