-
Notifications
You must be signed in to change notification settings - Fork 831
fix: Generate UXAML0001 error for invalid property values with valid C# fallback #21976
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
base: master
Are you sure you want to change the base?
Conversation
…th invalid Margin value Co-authored-by: dr1rrb <[email protected]>
|
|
|
|
…r URL Co-authored-by: dr1rrb <[email protected]>
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-21976/wasm-skia-net9/index.html |
|
@copilot Please move it to line 309, right after the |
…d_Object_Property Co-authored-by: dr1rrb <[email protected]>
|
@copilot src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Given_Parser.cs:335 This should be |
…n values Co-authored-by: dr1rrb <[email protected]>
Done in 4c7c4df - Updated the test to expect Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot Good 👍 Please do the same for:
Add tests for all of those cases |
…in XAML generator Co-authored-by: dr1rrb <[email protected]>
Done in 70e2cef - Added validation for:
Added tests:
|
|
@copilot src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs:4803-4822 Non, défait ça, le commenatire dit clairement que y'a un cas particulier pour Int32, remet Par contre tu n'a pas changé le |
…or2, Vector3, Point, Size, Matrix types Co-authored-by: dr1rrb <[email protected]>
Done in 3c8b545:
|
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-21976/wasm-skia-net9/index.html |
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21976/docs/index.html |
|
The build 185294 found UI Test snapshots differences: Details
|
|
|
|
@copilot The |
… generation Co-authored-by: dr1rrb <[email protected]>
Done in cdec53b - Replaced all
Also made |
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21976/docs/index.html |
src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Given_Parser.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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 improves the developer experience when using invalid XAML property values by generating proper UXAML0001 diagnostics at the correct XAML source location instead of CS0103 errors in generated C# code. The fix addresses the original issue where Margin="auto,0,0,0" would generate confusing C# compilation errors pointing to generated files rather than the XAML source.
Key changes:
- Added validation for numeric property values (Thickness, CornerRadius, GridLength, Double/Single, Vector2, Vector3, Point, Size, Matrix)
- Changed methods from static to instance to enable access to
AddError()for proper error reporting - Generates valid default values (e.g.,
new Thickness(0)) when validation fails, allowing compilation to continue and showing all errors at once
Reviewed changes
Copilot reviewed 2 out of 17 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| XamlFileGenerator.cs | Added validation logic to BuildThickness, BuildCornerRadius, BuildGridLength, GetFloatingPointLiteral, and SplitAndJoin methods; changed method signatures from static to instance to access AddError(); validates numeric components using double.TryParse with InvariantCulture |
| Given_Parser.cs | Added 5 new tests covering invalid values for Margin (Thickness), CornerRadius, GridLength (Height), Width (Double/Single), and RenderTransformOrigin (Point) |
| Out/Given_Parser/WhIn*/XamlCodeGenerator_*.cs | Generated test output files showing proper UXAML0001 diagnostics and valid fallback C# code with default values |
src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs
Outdated
Show resolved
Hide resolved
src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs
Outdated
Show resolved
Hide resolved
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21976/docs/index.html |
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21976/docs/index.html |
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
GitHub Issue: closes #21935
PR Type:
🐞 Bugfix
What is the current behavior? 🤔
Using invalid values like
Margin="auto,0,0,0"in XAML generatesCS0103: The name 'auto' does not exist in the current contextin generated code. The error points to the generated C# file instead of the XAML source, making it difficult for developers to understand and fix the issue. Additionally, the invalid generated code prevents successful compilation.What is the new behavior? 🚀
The XAML generator now validates property values and produces proper
UXAML0001diagnostics pointing to the correct location in the XAML file when an invalid value is detected. Instead of throwing exceptions that cause invalid C# generation, the generator usesAddError()to report errors while generating valid default values, allowing compilation to continue and all XAML errors to be shown at once.Validated property types:
new Thickness(0)on errornew CornerRadius(0)on errornew GridLength(0f, Pixel)on error0dor0fon errorSplitAndJoin, generates"0, 0"on errorExample:
Now produces:
UXAML0001: Invalid Thickness value 'auto,0,0,0'. Each component must be a valid numberwhile generatingnew Thickness(0)to ensure valid C# code.Changes:
XamlFileGenerator.BuildThickness()for Thickness values (changed to non-static to accessAddError)XamlFileGenerator.BuildCornerRadius()for CornerRadius values (changed to non-static to accessAddError)XamlFileGenerator.BuildGridLength()for GridLength values (changed to non-static to accessAddError)XamlFileGenerator.GetFloatingPointLiteral()for Double/Single valuesXamlFileGenerator.SplitAndJoin()for Vector2, Vector3, Point, Size, Matrix typesthrow new XamlGenerationException()withAddError()calls to allow continued code generation with default valuesWhen_Invalid_Margin_Value,When_Invalid_CornerRadius_Value,When_Invalid_GridLength_Value,When_Invalid_Double_Value,When_Invalid_Point_ValuePR Checklist ✅
Please check if your PR fulfills the following requirements:
Screenshots Compare Test Runresults.Other information ℹ️
Given_Parser.csinUno.UI.SourceGenerators.Tests, positioned right after theWhen_Invalid_Object_Propertytest for logical grouping of invalid XAML value tests.double.TryParse()to check component values before generating code.owner(XamlMemberDefinition) is available to ensure backward compatibility with internal calls.AddError()instead of throwing exceptions to ensure valid C# code is always generated, preventing CS0103 compilation errors while still reporting UXAML0001 diagnostics at the correct XAML locations.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.