ILLink.RoslynAnalyzer: fix hole for new constraint#119291
Merged
sbomer merged 4 commits intodotnet:mainfrom Sep 15, 2025
Merged
ILLink.RoslynAnalyzer: fix hole for new constraint#119291sbomer merged 4 commits intodotnet:mainfrom
sbomer merged 4 commits intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a hole in the ILLink.RoslynAnalyzer's handling of generic constraints. The analyzer was not properly detecting required capability violations (like RequiresDynamicCode or RequiresAssemblyFiles) when accessed through new() constraints on generic type parameters. The fix moves the new constraint processing from a separate code path into the existing GenericArgumentDataFlow class, ensuring that implicit constructor calls are properly analyzed.
Key changes:
- Consolidates generic constraint processing into
GenericArgumentDataFlow - Adds proper detection of
new()constraint violations for required capabilities - Updates test cases to verify the fix works correctly
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| RequiresOnClass.cs | Adds test cases for new constraint processing and updates expected warnings |
| TrimAnalysisVisitor.cs | Updates method signatures to pass DataFlowAnalyzerContext |
| TrimAnalysisMethodCallPattern.cs | Updates HandleCall invocation with new parameters |
| TrimAnalysisGenericInstantiationPattern.cs | Refactors to use GenericArgumentDataFlow instance instead of static methods |
| TrimAnalysisAssignmentPattern.cs | Updates RequireDynamicallyAccessedMembersAction constructor call |
| RequireDynamicallyAccessedMembersAction.cs | Adds DataFlowAnalyzerContext and FeatureContext parameters |
| HandleCallAction.cs | Updates constructor to accept and pass through new context parameters |
| GenericArgumentDataFlow.cs | Major refactor from static to instance class with new constraint processing |
| RequiresAnalyzerBase.cs | Removes old generic name syntax processing logic |
| DynamicallyAccessedMembersAnalyzer.cs | Updates to use new GenericArgumentDataFlow instance |
src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/GenericArgumentDataFlow.cs
Outdated
Show resolved
Hide resolved
This was referenced Sep 9, 2025
jtschuster
approved these changes
Sep 15, 2025
Member
jtschuster
left a comment
There was a problem hiding this comment.
Sorry I got to this so late!
Member
Author
|
No problem, thanks for the review! |
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.
The new constraint processing was happening in a separate code path from the other generic argument processing, and that code path didn't see the implicit call to the base ctor (because it didn't use the IOperation tree). This fixes it by moving the new constraint processing into
GenericArgumentDataFlow.Unlike ILC, the analyzer can't just treat
new()the same asPublicParameterlessConstructors, because it needs to produce analysis warnings forRequiresDynamicCodeorRequiresAssemblyFilesaccessed vianew()constraint, even when trim analysis is disabled (the annotation is treated as reflection access, butnew()is not).Fixes #118869