diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
index 2851e3eea..d7153d8bb 100644
--- a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
+++ b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
@@ -252,6 +252,7 @@
+
diff --git a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
index d28edc76a..f34b96b5b 100644
--- a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
+++ b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
@@ -599,6 +599,17 @@ namespace ICSharpCode.Decompiler.Tests
await RunForLibrary(cscOptions: cscOptions);
}
+ [Test]
+ public async Task OptionalArgumentsDisabled([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
+ {
+ await RunForLibrary(
+ cscOptions: cscOptions,
+ configureDecompiler: settings => {
+ settings.OptionalArguments = false;
+ }
+ );
+ }
+
[Test]
public async Task Comparisons([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
{
diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArgumentsDisabled.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArgumentsDisabled.cs
new file mode 100644
index 000000000..b33456f2c
--- /dev/null
+++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArgumentsDisabled.cs
@@ -0,0 +1,19 @@
+namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
+{
+ public class OptionalArgumentsDisabled
+ {
+ public void Test()
+ {
+ MixedArguments("123", 0, 0);
+ OnlyOptionalArguments(0, 0);
+ }
+
+ public void MixedArguments(string msg, int a = 0, int b = 0)
+ {
+ }
+
+ public void OnlyOptionalArguments(int a = 0, int b = 0)
+ {
+ }
+ }
+}
diff --git a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs
index f4fa1fb03..e1ee32c3b 100644
--- a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs
+++ b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs
@@ -967,7 +967,8 @@ namespace ICSharpCode.Decompiler.CSharp
}
else
{
- firstOptionalArgumentIndex = -2;
+ if (firstOptionalArgumentIndex != -1)
+ firstOptionalArgumentIndex = -2;
}
if (expressionBuilder.settings.ExpandParamsArguments && parameter.IsParams && i + 1 == callArguments.Count && argumentToParameterMap == null)
{