Skip to content

Commit 6400b32

Browse files
Merge pull request #3533 from MSchmoecker/fix-disabled-optional-arguments
Fix incorrect argument removal if OptionalArguments is false
2 parents 99165b7 + 850ffe5 commit 6400b32

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@
252252
<Compile Include="TestCases\Pretty\ConstantsTests.cs" />
253253
<Compile Include="TestCases\Pretty\CS73_StackAllocInitializers.cs" />
254254
<Compile Include="TestCases\Pretty\OptionalArguments.cs" />
255+
<Compile Include="TestCases\Pretty\OptionalArgumentsDisabled.cs" />
255256
<Compile Include="TestCases\Pretty\CustomShortCircuitOperators.cs" />
256257
<Compile Include="TestCases\Pretty\ReduceNesting.cs" />
257258
<Compile Include="TestCases\Pretty\InterfaceTests.cs" />

ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,17 @@ public async Task OptionalArguments([ValueSource(nameof(defaultOptions))] Compil
599599
await RunForLibrary(cscOptions: cscOptions);
600600
}
601601

602+
[Test]
603+
public async Task OptionalArgumentsDisabled([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
604+
{
605+
await RunForLibrary(
606+
cscOptions: cscOptions,
607+
configureDecompiler: settings => {
608+
settings.OptionalArguments = false;
609+
}
610+
);
611+
}
612+
602613
[Test]
603614
public async Task Comparisons([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
604615
{
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
2+
{
3+
public class OptionalArgumentsDisabled
4+
{
5+
public void Test()
6+
{
7+
MixedArguments("123", 0, 0);
8+
OnlyOptionalArguments(0, 0);
9+
}
10+
11+
public void MixedArguments(string msg, int a = 0, int b = 0)
12+
{
13+
}
14+
15+
public void OnlyOptionalArguments(int a = 0, int b = 0)
16+
{
17+
}
18+
}
19+
}

ICSharpCode.Decompiler/CSharp/CallBuilder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,8 @@ private ArgumentList BuildArgumentList(ExpectedTargetDetails expectedTargetDetai
967967
}
968968
else
969969
{
970-
firstOptionalArgumentIndex = -2;
970+
if (firstOptionalArgumentIndex != -1)
971+
firstOptionalArgumentIndex = -2;
971972
}
972973
if (expressionBuilder.settings.ExpandParamsArguments && parameter.IsParams && i + 1 == callArguments.Count && argumentToParameterMap == null)
973974
{

0 commit comments

Comments
 (0)