-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[release/10.0] Add warning for annotated extension property (#120005) #120118
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
Conversation
Fixes dotnet#119113 by adding a new warning that is shown by the Roslyn analyzer when attempting to annotate an extension property with DynamicallyAccessedMembersAttribute. The warning is also produced by ILLink and ILC, but only when the compiler-generated extension metadata type (which contains the property in IL) is referenced, for example via reflection or when the assembly is rooted. So in practice this will be caught just by the analyzer. See comments in the code that explain some nuances of the test approach (we need a way to assert `ExpectedWarning`s on the extension properties, but not the compiler-generated methods in the extension metadata type). Testing this uncovered a test bug which was hiding dotnet#120004.
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 adds a warning for DynamicallyAccessedMembers attribute on extension properties, which was previously silently ignored. The change ensures that users are informed when their annotations have no effect on C# 14 extension properties.
Key changes:
- Introduces IL2127 warning when
DynamicallyAccessedMembersis applied to extension properties - Updates test infrastructure to support
SetupRootEntireAssemblyattribute as a replacement for manual linker arguments - Adds proper handling of extension properties in dataflow analysis and test result checking
Reviewed Changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/tools/illink/src/linker/Linker.Dataflow/FlowAnnotations.cs | Adds check for extension properties and emits IL2127 warning |
| src/tools/illink/src/ILLink.RoslynAnalyzer/DynamicallyAccessedMembersAnalyzer.cs | Adds analyzer support for detecting annotated extension properties |
| src/tools/illink/src/ILLink.Shared/DiagnosticId.cs | Defines new IL2127 diagnostic ID |
| src/tools/illink/src/ILLink.Shared/SharedStrings.resx | Adds warning message text for IL2127 |
| src/tools/illink/src/ILLink.Shared/DataFlow/CompilerGeneratedNames.cs | Adds utility method to identify extension types |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/FlowAnnotations.cs | Adds same extension property check for NativeAOT |
| src/tools/illink/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupRootEntireAssemblyAttribute.cs | New test attribute for rooting entire assemblies |
| src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadataProvider.cs | Processes new SetupRootEntireAssembly attribute |
| src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ExtensionMembersDataFlow.cs | Updates test to expect IL2127 warnings for extension properties |
src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs
Show resolved
Hide resolved
src/coreclr/tools/aot/ILCompiler.Trimming.Tests/TestCasesRunner/ResultChecker.cs
Show resolved
Hide resolved
* Unify ResultChecker logic Ports some changes to the ResultChecker logic from ILLink over to the ILC test infra. Includes dotnet@80414e9, and some other small fixes. * Clean up
|
/ba-g Known issues dotnet/dnceng#3008 dotnet/dnceng#1883 |
Backport of #120005 to 10.0.
Customer Impact
This fixes an issue where
DynamicallyAccessedMemberson extension properties (new in .NET 10) is silently ignored. The existing behavior violates user expectations because the attribute has no effect. With the fix, this will be a warning.Regression
Testing
Updated tests to validate the new behavior. This behavior was known and tested in the initial change that introduced support for extension members. and we decided after the fact that this should produce a warning.
Risk
Low. This fix is added for completeness in a new .NET 10 feature (trimming support for C# 14 extensions) and does not impact code that doesn't use C# 14 extensions.