Skip to content

Fix ILLink analyzer assertion for delegates with default parameters#126868

Merged
MichalStrehovsky merged 2 commits intomainfrom
copilot/fix-assertion-in-ci
Apr 14, 2026
Merged

Fix ILLink analyzer assertion for delegates with default parameters#126868
MichalStrehovsky merged 2 commits intomainfrom
copilot/fix-assertion-in-ci

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 14, 2026

Description

The ILLink Roslyn analyzer's dataflow analysis hits a Debug.Assert (crash in CI) when encountering a delegate type with a default parameter value, e.g.:

delegate ParallelQuery<int> Operation(int start, int count, Operation source = null);

Roslyn generates an operation block for the default parameter initializer whose OwningSymbol is the delegate's INamedTypeSymbol, not an IMethodSymbol/IFieldSymbol/IPropertySymbol as the analyzer expects.

Fix: Skip interprocedural dataflow analysis in LocalDataFlowAnalysis.InterproceduralAnalyze() when the owning symbol is a delegate type (INamedTypeSymbol { TypeKind: TypeKind.Delegate }). These operation blocks contain only simple constant initializers with no interesting dataflow for trim analysis.

Test: Added a delegate void DelegateWithDefaultParameter(Type type = null) to the existing DelegateCreation test class in AnnotatedMembersAccessedViaReflection.cs.

Copilot AI and others added 2 commits April 14, 2026 07:28
…assert to throw

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/af9c6f4b-3927-402e-bc3c-e61667fc3e5e

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/af9c6f4b-3927-402e-bc3c-e61667fc3e5e

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 14, 2026 08:01
Copilot AI review requested due to automatic review settings April 14, 2026 08:02
@dotnet-policy-service dotnet-policy-service bot added the linkable-framework Issues associated with delivering a linker friendly framework label Apr 14, 2026
@MichalStrehovsky MichalStrehovsky marked this pull request as ready for review April 14, 2026 08:02
Copilot AI review requested due to automatic review settings April 14, 2026 08:02
@MichalStrehovsky MichalStrehovsky added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Apr 14, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

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

Fixes a Roslyn ILLink analyzer debug assertion triggered by delegate types that declare optional (defaulted) parameters, where Roslyn reports an operation block whose OwningSymbol is the delegate INamedTypeSymbol instead of a method/field/property symbol.

Changes:

  • Skip LocalDataFlowAnalysis.InterproceduralAnalyze() for operation blocks owned by delegate types (INamedTypeSymbol { TypeKind: Delegate }) to avoid constructing MethodBodyValue with an unsupported symbol kind.
  • Add a regression test case by introducing a delegate with an optional parameter into an existing dataflow test class.

Reviewed changes

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

File Description
src/tools/illink/src/ILLink.RoslynAnalyzer/DataFlow/LocalDataFlowAnalysis.cs Early-exits interprocedural analysis when Roslyn provides a delegate-type owning symbol for optional-parameter initializer blocks.
src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/AnnotatedMembersAccessedViaReflection.cs Adds a delegate-with-default-parameter declaration to exercise the analyzer path that previously asserted.

@MichalStrehovsky
Copy link
Copy Markdown
Member

/ba-g wasm timeout

@MichalStrehovsky MichalStrehovsky merged commit e697a30 into main Apr 14, 2026
110 of 112 checks passed
@MichalStrehovsky MichalStrehovsky deleted the copilot/fix-assertion-in-ci branch April 14, 2026 21:48
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.

4 participants