Uh oh!
There was an error while loading. Please reload this page.
ILLink.RoslynAnalyzer: fix hole for new constraint - #119291
Conversation
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 |
Uh oh!
There was an error while loading. Please reload this page.
jtschuster
left a comment
There was a problem hiding this comment.
Sorry I got to this so late!
sbomer
commented
Sep 15, 2025
No problem, thanks for the review! |
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