Skip to content

Conversation

sbomer
Copy link
Member

@sbomer sbomer commented Aug 22, 2025

Fixes #115949

This adds Roslyn analyzer support for C# 14 extensions. A few notes on the behavior:

New tests uncovered an analyzer issue with operators in the (extension or not): #119110. This change includes test coverage for non-extension operators.

@Copilot Copilot AI review requested due to automatic review settings August 22, 2025 18:17
@sbomer sbomer requested a review from marek-safar as a code owner August 22, 2025 18:17
@github-actions github-actions bot added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Aug 22, 2025
@sbomer sbomer requested a review from a team August 22, 2025 18:17
@dotnet-policy-service dotnet-policy-service bot added the linkable-framework Issues associated with delivering a linker friendly framework label Aug 22, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/illink
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

@Copilot Copilot AI left a 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 trim analyzer support for C# 14 extensions by implementing comprehensive handling of the new extension syntax introduced in C# 14. The key changes enable proper data flow analysis and warning generation for extension members while addressing compiler-generated artifacts.

  • Adds test coverage for both traditional extension methods and new C# 14 extension members
  • Updates the trim analysis infrastructure to handle extension parameters on types
  • Implements workarounds for compiler-generated types that inherit attributes from extension members

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs Adds workaround to skip attribute validation for compiler-generated extension member types
src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ExtensionsDataFlow.cs New test case for traditional extension method data flow analysis
src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ExtensionMembersDataFlow.cs New test case for C# 14 extension members data flow analysis
src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/DataFlowTests.cs Adds test methods for the new extension data flow test cases
src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/TrimAnalysisVisitor.cs Updates parameter handling to support extension parameters on types
src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/ParameterProxy.cs Enhances parameter proxy to handle extension parameters with proper indexing
src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/MethodParameterValue.cs Removes obsolete constructors for method parameter values
src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/FlowAnnotations.cs Updates parameter annotation retrieval for extension methods
src/tools/illink/src/ILLink.RoslynAnalyzer/IMethodSymbolExtensions.cs Adds extension parameter detection and parameter counting logic
src/tools/illink/src/ILLink.RoslynAnalyzer/ILLink.RoslynAnalyzer.csproj Reorders NoWarn directives and removes conditional compilation warning suppression
src/tools/illink/src/ILLink.RoslynAnalyzer/DataFlow/LocalDataFlowVisitor.cs Updates method and property call handling for extension parameters
src/coreclr/tools/aot/ILCompiler.Trimming.Tests/TestCasesRunner/ResultChecker.cs Duplicates the compiler-generated type workaround for NativeAOT testing
eng/Versions.props Updates Microsoft.CodeAnalysis version from 4.8.0 to 4.14.0

Copy link
Member

@jtschuster jtschuster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Including extension operators, and plain operators.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Tools-ILLink .NET linker development as well as trimming analyzers linkable-framework Issues associated with delivering a linker friendly framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

System.InvalidCastException in DynamicallyAccessedMembersAnalyzer when using C# 14 extensions
2 participants