Fix ILLink analyzer assertion for delegates with default parameters#126868
Merged
MichalStrehovsky merged 2 commits intomainfrom Apr 14, 2026
Merged
Fix ILLink analyzer assertion for delegates with default parameters#126868MichalStrehovsky merged 2 commits intomainfrom
MichalStrehovsky merged 2 commits intomainfrom
Conversation
…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 created this pull request from a session on behalf of
MichalStrehovsky
April 14, 2026 08:02
View session
Contributor
|
Tagging subscribers to this area: @agocke, @dotnet/illink |
Contributor
There was a problem hiding this comment.
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 constructingMethodBodyValuewith 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. |
sbomer
approved these changes
Apr 14, 2026
Member
|
/ba-g wasm timeout |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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.:Roslyn generates an operation block for the default parameter initializer whose
OwningSymbolis the delegate'sINamedTypeSymbol, not anIMethodSymbol/IFieldSymbol/IPropertySymbolas 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 existingDelegateCreationtest class inAnnotatedMembersAccessedViaReflection.cs.