From 7b9460a2f07528371c1b8268963fd4e21f6435ce Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 14 Apr 2026 07:28:26 +0000 Subject: [PATCH 1/2] Add test for delegate with default parameter and temporarily convert 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> --- .../src/ILLink.RoslynAnalyzer/DataFlow/MethodBodyValue.cs | 3 ++- .../DataFlow/AnnotatedMembersAccessedViaReflection.cs | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/tools/illink/src/ILLink.RoslynAnalyzer/DataFlow/MethodBodyValue.cs b/src/tools/illink/src/ILLink.RoslynAnalyzer/DataFlow/MethodBodyValue.cs index a504db87353f34..5e3979469f2c9b 100644 --- a/src/tools/illink/src/ILLink.RoslynAnalyzer/DataFlow/MethodBodyValue.cs +++ b/src/tools/illink/src/ILLink.RoslynAnalyzer/DataFlow/MethodBodyValue.cs @@ -20,7 +20,8 @@ namespace ILLink.RoslynAnalyzer.DataFlow public MethodBodyValue(ISymbol owningSymbol, ControlFlowGraph cfg) { - Debug.Assert(owningSymbol is (IMethodSymbol or IFieldSymbol or IPropertySymbol)); + if (owningSymbol is not (IMethodSymbol or IFieldSymbol or IPropertySymbol)) + throw new InvalidOperationException($"Unexpected owning symbol type '{owningSymbol.GetType()}' for MethodBodyValue."); OwningSymbol = owningSymbol; ControlFlowGraph = cfg; } diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/AnnotatedMembersAccessedViaReflection.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/AnnotatedMembersAccessedViaReflection.cs index f719ae746f7434..4daf4aec7f545e 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/AnnotatedMembersAccessedViaReflection.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/AnnotatedMembersAccessedViaReflection.cs @@ -890,6 +890,11 @@ class DelegateCreation static event Action Event; + // Delegate with a default parameter value. + // The default parameter generates an operation block whose OwningSymbol + // is the delegate type (INamedTypeSymbol), not a method. + delegate void DelegateWithDefaultParameter(Type type = null); + static void TestField() { var d = new UnannotatedDelegate(field); From 111051270dfc9fbf1fcf01c60e6eec756c6fb43f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 14 Apr 2026 07:57:02 +0000 Subject: [PATCH 2/2] Fix ILLink analyzer assertion for delegates with default parameters Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/af9c6f4b-3927-402e-bc3c-e61667fc3e5e Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com> --- .../ILLink.RoslynAnalyzer/DataFlow/LocalDataFlowAnalysis.cs | 6 ++++++ .../src/ILLink.RoslynAnalyzer/DataFlow/MethodBodyValue.cs | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/tools/illink/src/ILLink.RoslynAnalyzer/DataFlow/LocalDataFlowAnalysis.cs b/src/tools/illink/src/ILLink.RoslynAnalyzer/DataFlow/LocalDataFlowAnalysis.cs index 3b87c62452fd28..730e43e77560de 100644 --- a/src/tools/illink/src/ILLink.RoslynAnalyzer/DataFlow/LocalDataFlowAnalysis.cs +++ b/src/tools/illink/src/ILLink.RoslynAnalyzer/DataFlow/LocalDataFlowAnalysis.cs @@ -80,6 +80,12 @@ public bool InterproceduralAnalyze() return succeeded; } + // Delegate types with default parameter values produce operation blocks whose + // OwningSymbol is the delegate INamedTypeSymbol. These blocks contain only + // simple constant initializers with no interesting dataflow, so skip them. + if (Context.OwningSymbol is INamedTypeSymbol { TypeKind: TypeKind.Delegate }) + return succeeded; + Debug.Assert(Context.OwningSymbol is not IMethodSymbol methodSymbol || methodSymbol.MethodKind is not (MethodKind.LambdaMethod or MethodKind.LocalFunction)); var startMethod = new MethodBodyValue(Context.OwningSymbol, Context.GetControlFlowGraph(OperationBlock)); diff --git a/src/tools/illink/src/ILLink.RoslynAnalyzer/DataFlow/MethodBodyValue.cs b/src/tools/illink/src/ILLink.RoslynAnalyzer/DataFlow/MethodBodyValue.cs index 5e3979469f2c9b..a504db87353f34 100644 --- a/src/tools/illink/src/ILLink.RoslynAnalyzer/DataFlow/MethodBodyValue.cs +++ b/src/tools/illink/src/ILLink.RoslynAnalyzer/DataFlow/MethodBodyValue.cs @@ -20,8 +20,7 @@ namespace ILLink.RoslynAnalyzer.DataFlow public MethodBodyValue(ISymbol owningSymbol, ControlFlowGraph cfg) { - if (owningSymbol is not (IMethodSymbol or IFieldSymbol or IPropertySymbol)) - throw new InvalidOperationException($"Unexpected owning symbol type '{owningSymbol.GetType()}' for MethodBodyValue."); + Debug.Assert(owningSymbol is (IMethodSymbol or IFieldSymbol or IPropertySymbol)); OwningSymbol = owningSymbol; ControlFlowGraph = cfg; }