Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
<Compile Include="TestCases\ILPretty\Issue3552.cs" />
<Compile Include="TestCases\Pretty\ExpandParamsArgumentsDisabled.cs" />
<Compile Include="TestCases\Pretty\ExtensionProperties.cs" />
<Compile Include="TestCases\Pretty\Issue3541.cs" />
<None Include="TestCases\ILPretty\Issue3504.cs" />
<Compile Include="TestCases\ILPretty\MonoFixed.cs" />
<Compile Include="TestCases\Pretty\Comparisons.cs" />
Expand Down
14 changes: 14 additions & 0 deletions ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ public void AllFilesHaveTests()
CompilerOptions.Optimize | CompilerOptions.UseRoslynLatest,
};

static readonly CompilerOptions[] roslyn4OrNewerWithNet40Options =
{
CompilerOptions.UseRoslynLatest | CompilerOptions.TargetNet40,
CompilerOptions.Optimize | CompilerOptions.UseRoslynLatest | CompilerOptions.TargetNet40,
CompilerOptions.UseRoslynLatest,
CompilerOptions.Optimize | CompilerOptions.UseRoslynLatest,
};

static readonly CompilerOptions[] roslyn4OrNewerOptions =
{
CompilerOptions.UseRoslynLatest,
Expand Down Expand Up @@ -664,6 +672,12 @@ public async Task Issue3483([ValueSource(nameof(defaultOptions))] CompilerOption
await RunForLibrary(cscOptions: cscOptions | CompilerOptions.CheckForOverflowUnderflow, configureDecompiler: settings => settings.CheckForOverflowUnderflow = true);
}

[Test]
public async Task Issue3541([ValueSource(nameof(roslyn4OrNewerWithNet40Options))] CompilerOptions cscOptions)
{
await RunForLibrary(cscOptions: cscOptions);
}

[Test]
public async Task AssemblyCustomAttributes([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
{
Expand Down
15 changes: 15 additions & 0 deletions ICSharpCode.Decompiler.Tests/TestCases/Pretty/Issue3541.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
internal class Issue3541
{
private void Test(string format)
{
TestLocal();

void TestLocal(int a = 0)
{
a.ToString(format);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -566,13 +566,18 @@ static T FindCommonAncestorInstruction<T>(ILInstruction a, ILInstruction b)
}

internal static bool IsClosureParameter(IParameter parameter, ITypeResolveContext context)
{
return IsClosureParameter(parameter, context.CurrentTypeDefinition);
}

internal static bool IsClosureParameter(IParameter parameter, ITypeDefinition currentTypeDefinition)
{
if (parameter.Type is not ByReferenceType brt)
return false;
var type = brt.ElementType.GetDefinition();
return type != null
&& type.Kind == TypeKind.Struct
&& TransformDisplayClassUsage.IsPotentialClosure(context.CurrentTypeDefinition, type);
&& TransformDisplayClassUsage.IsPotentialClosure(currentTypeDefinition, type);
}

LocalFunctionMethod ReduceToLocalFunction(IMethod method, int typeParametersToRemove)
Expand Down
4 changes: 4 additions & 0 deletions ICSharpCode.Decompiler/TypeSystem/TypeSystemExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Linq;
using System.Reflection.Metadata;

using ICSharpCode.Decompiler.IL.Transforms;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.Semantics;
using ICSharpCode.Decompiler.TypeSystem.Implementation;
Expand Down Expand Up @@ -681,6 +682,9 @@ public static bool IsDefaultValueAssignmentAllowed(this IParameter parameter)
if (otherParameter == parameter)
break;

if (LocalFunctionDecompiler.IsClosureParameter(otherParameter, otherParameter.Owner.DeclaringTypeDefinition))
continue;

if (DefaultValueAssignmentAllowedIndividual(otherParameter) || otherParameter.IsParams)
continue;

Expand Down
Loading