Repository navigation
[SourceGen] Report correct location for expression parse errors - #36165
Merged
Merged
Conversation
Contributor
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 36165Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 36165" |
StephaneDelcroix
temporarily deployed
to
gh-aw-agents
June 26, 2026 13:35 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a SourceGen diagnostic-location bug where expression/markup parse errors (e.g., missing closing }) were incorrectly reported at the file root (1,1) instead of the offending expression’s actual line/column.
Changes:
- Capture the original markup text and derive diagnostic
LocationfromIXmlLineInfowhen reportingMAUIG1003/MAUIG1001inExpandMarkupsVisitor.ParseExpression. - Add unit tests validating
MAUIG1003reports on the expression’s line (and not column 0) for both XEPR-style expressions and markup extensions.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Controls/src/SourceGen/Visitors/ExpandMarkupsVisitor.cs | Uses line info to create accurate diagnostic locations for expression/markup parse errors. |
| src/Controls/tests/SourceGen.UnitTests/Maui36158Tests.cs | Adds regression tests asserting diagnostics point to the expression’s line/column rather than (1,1). |
StephaneDelcroix
temporarily deployed
to
gh-aw-agents
June 26, 2026 13:37 — with
GitHub Actions
Inactive
StephaneDelcroix
temporarily deployed
to
gh-aw-agents
June 26, 2026 13:38 — with
GitHub Actions
Inactive
StephaneDelcroix
temporarily deployed
to
gh-aw-agents
June 26, 2026 13:38 — with
GitHub Actions
Inactive
This was referenced Jun 29, 2026
Fixes #36158 When a markup / XAML C# Expression failed to parse (e.g. a missing closing '}'), the source generator reported MAUIG1003 / MAUIG1001 at the file root (1,1) instead of the line/column of the offending expression. ExpandMarkupsVisitor.ParseExpression built the diagnostic location from an empty TextSpan / LinePositionSpan (three '//FIXME fix location' spots), ignoring the xmlLineInfo parameter it already receives. This derives the location from xmlLineInfo via the existing LocationHelpers.LocationCreate helper, with a safe fallback when line info or the relative path is unavailable. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
StephaneDelcroix
force-pushed
the
fix-36158-expression-diagnostic-location
branch
from
July 7, 2026 08:34
9c42b2e to
bb51712
Compare
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jfversluis
approved these changes
Jul 8, 2026
This was referenced Jul 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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!
Fixes #36158
Summary
When a markup / XAML C# Expression fails to parse (e.g. a missing closing
}), the source generator reportedMAUIG1003: Expression must end with '}'(and the siblingMAUIG1001parse error) at the file root(1,1)instead of the actual line/column of the offending expression.Root cause
ExpandMarkupsVisitor.ParseExpressionbuilt the diagnosticlocationfrom an emptyTextSpan/LinePositionSpanin three places (each marked//FIXME fix location), ignoring thexmlLineInfoparameter it already receives.new LinePositionSpan()defaults to line 0 / char 0, which renders as(1,1).Fix
Derive the location from
xmlLineInfousing the existingLocationHelpers.LocationCreatehelper (the same helper already used throughout this file and the rest of the SourceGen), via a smallCreateExpressionLocationmethod. It falls back gracefully to the previous behavior when line info or the relative path is unavailable.The diagnostic now points at the expression's actual line, e.g.
MainPage.xaml(33,…)instead ofMainPage.xaml(1,1).Tests
Added
Maui36158Tests(inControls.SourceGen.UnitTests) with two cases:{IsActive ? 'Status: Active' : 'Status: Idle'— now reportsMAUIG1003on the expression's line.{StaticResource MissingBrace— likewise reports on the correct line.Both tests fail without the fix (reported line
0) and pass with it. The fullControls.SourceGen.UnitTestssuite (218 tests) passes with no regressions.Notes
This addresses only the diagnostic-location bug. The related issues #36157 (stale
MAUIG1003underdotnet watch), #36156 (rude-edit hot reload), and #36155 (XEPR nested-string / ternary parsing) are out of scope.