Skip to content

[XSG] Fix FlexBasis source generator to emit float literals#32696

Merged
StephaneDelcroix merged 2 commits into
mainfrom
dev/stdelc/fix32680
Nov 18, 2025
Merged

[XSG] Fix FlexBasis source generator to emit float literals#32696
StephaneDelcroix merged 2 commits into
mainfrom
dev/stdelc/fix32680

Conversation

@StephaneDelcroix
Copy link
Copy Markdown
Contributor

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 of Change

Fixes #32680

The FlexBasis constructor expects float parameters, but the source generator was emitting double literals without the 'f' suffix, causing compilation errors when using XAML source generation with FlexLayout.Basis.

Before (broken):

new global::Microsoft.Maui.Layouts.FlexBasis(0.33, true)  // double - compile error

After (fixed):

new global::Microsoft.Maui.Layouts.FlexBasis(0.33f, true)  // float - correct

Changes

  1. FlexBasisConverter.cs: Added f suffix to numeric literals on lines 33 and 39

    • Percentage values: FlexLayout.Basis="33%"new FlexBasis(0.33f, true)
    • Decimal values: FlexLayout.Basis="0.5"new FlexBasis(0.5f, false)
    • Integer values: FlexLayout.Basis="100"new FlexBasis(100f, false)
  2. FlexLayoutTests.cs: Added comprehensive unit tests for FlexLayout properties

    • Tests FlexBasis with percentage, decimal, and integer values
    • Tests culture-independent generation (en-US, fr-FR, de-DE)
    • Tests Grow and Shrink properties
    • Uses Assert.Equal(expected, generated, ignoreLineEndingDifferences: true) to verify complete generated code

Pattern

The fix follows the same pattern used in:

  • ColorConverter.cs (line 25) which adds f suffix to color component values
  • NodeSGExtensions.cs (line 357) which handles System.Single with F suffix

Issues Fixed

Fixes #32680

Copilot AI review requested due to automatic review settings November 18, 2025 10:02
@StephaneDelcroix StephaneDelcroix added this to the .NET 10.0 SR2 milestone Nov 18, 2025
@StephaneDelcroix StephaneDelcroix changed the title Fix FlexBasis source generator to emit float literals [XSG] Fix FlexBasis source generator to emit float literals Nov 18, 2025
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

This PR fixes a compilation error in the XAML source generator where FlexBasis constructor calls were emitting double literals instead of float literals. The FlexBasis constructor expects float parameters, but the source generator was generating numeric values without the 'f' suffix, causing implicit conversion issues.

Key Changes

  • Added 'f' suffix to numeric literals in FlexBasisConverter.cs for both percentage and absolute values
  • Added comprehensive unit tests covering percentage, decimal, and integer FlexBasis values
  • Verified culture-independent code generation across en-US, fr-FR, and de-DE locales

Reviewed Changes

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

File Description
src/Controls/src/SourceGen/TypeConverters/FlexBasisConverter.cs Added 'f' suffix to float literals on lines 33 and 39, ensuring generated code matches FlexBasis constructor signature
src/Controls/tests/SourceGen.UnitTests/FlexLayoutTests.cs Added comprehensive test coverage for FlexLayout.Basis with percentage/decimal/integer values, plus tests for Grow/Shrink properties and culture-independence

@StephaneDelcroix
Copy link
Copy Markdown
Contributor Author

/rebase

@github-actions github-actions Bot force-pushed the dev/stdelc/fix32680 branch from 72e6447 to e0fabbf Compare November 18, 2025 11:22
simonrozsival
simonrozsival previously approved these changes Nov 18, 2025
Fixes #32680

The FlexBasis constructor expects float parameters, but the source
generator was emitting double literals without the 'f' suffix, causing
compilation errors.

Changes:
- Added 'f' suffix to FlexBasis numeric literals in FlexBasisConverter
- Added comprehensive unit tests for FlexLayout properties

The fix follows the same pattern used in ColorConverter and matches
how primitive float values are handled in NodeSGExtensions.
- Add tests for all FlexLayout-specific attached properties
- Add tests for Wrap, Direction, Basis, Grow, Shrink, AlignSelf, and Order
- Add tests for layout invalidation when properties change
- Improve test coverage for FlexLayout code generation scenarios
@StephaneDelcroix StephaneDelcroix merged commit b9463d6 into main Nov 18, 2025
62 checks passed
@StephaneDelcroix StephaneDelcroix deleted the dev/stdelc/fix32680 branch November 18, 2025 18:25
@PureWeen PureWeen added the area-xaml XAML, CSS, Triggers, Behaviors label Dec 17, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Jan 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-xaml XAML, CSS, Triggers, Behaviors

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[.NET 10] Xaml Source Gen - Argument 1: cannot convert from 'double' to 'float' - FlexLayout.Basis

4 participants