feat(generator): intercept calls whose types generated code cannot name - #167
Merged
Merged
Conversation
- Intercept calls whose selector result is an anonymous or private type, by taking the result type as a generic parameter. - Intercept calls on private or protected types and members from inside the caller's partial class, by placing the generated code in a private nested class of that class. - Intercept calls made through the caller's type parameters, by generating code that is generic over them. - Fail the build at the call when it cannot be intercepted. RXUIBIND001, 003, 006, 009, 012, 013, 015, 016 and 021 are errors. Every call they report throws at run time. - Keep RXUIBIND021 a warning for a member that only another source generator declares. - Stop emitting broken code for anonymous result types, file-local types and BindCommand with a stored parameter expression.
glennawatson
enabled auto-merge (squash)
October 4, 2026 01:57
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #167 +/- ##
==========================================
+ Coverage 99.23% 99.28% +0.04%
==========================================
Files 396 403 +7
Lines 14469 15028 +559
Branches 2065 2227 +162
==========================================
+ Hits 14359 14920 +561
+ Misses 110 108 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



Summary
The generator now intercepts calls whose types it could not name before, and fails the build at any call it still cannot generate.
T, are intercepted with code that is generic over them.Why
A call naming a type the generated code could not reach was skipped with a warning, and the call then threw
InvalidOperationExceptionat run time. An anonymous result type was not skipped at all, and the generator wrote the anonymous type's display name into the generated source, which then failed to compile.Breaking changes
RXUIBIND001, 003, 006, 009, 012, 013, 015, 016 and 021 are now errors. Every call they report already threw at run time, so only code that was already broken stops compiling. To fix such a call, make the types or members it uses reachable (internal, or inside a partial class), or call the matching
*Unsafemethod. RXUIBIND021 stays a warning when the member is declared only by another source generator. This ships as a minor release.How this was verified
New generator, analyzer and runtime tests cover each intercepted shape with real values for every generated API, the error path on the Roslyn 4.8 build and with interceptors off, and the shapes that still cannot be intercepted. The AOT example could not be linked locally without clang.
Notes for the reviewer
Start with
Helpers/CallSiteHosting.csandInvocationPipeline.cs, which decide whether a call is intercepted with a generic result, hosted in the caller's partial class, or reported.CodeGeneration/HostedCallSiteEmitter.csandHostedSourceReader.csemit the hosted code. The per-API emitters are unchanged. The analyzer changes skip any call the generator intercepts, and theAnalyzerReleasesfiles record the severity changes. The test and snapshot files are mechanical.Checklist