From c6883308972686a9abd7916697aa821af6183c15 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Wed, 6 Feb 2019 16:04:35 +0200 Subject: [PATCH] Fixed the generated C# for parameters initialized with {}. Signed-off-by: Dimitar Dobrev --- src/Generator/Passes/HandleDefaultParamValuesPass.cs | 2 +- tests/CSharp/CSharp.Tests.cs | 1 + tests/CSharp/CSharp.cpp | 4 ++++ tests/CSharp/CSharp.h | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Generator/Passes/HandleDefaultParamValuesPass.cs b/src/Generator/Passes/HandleDefaultParamValuesPass.cs index ee299f8c..f668d140 100644 --- a/src/Generator/Passes/HandleDefaultParamValuesPass.cs +++ b/src/Generator/Passes/HandleDefaultParamValuesPass.cs @@ -194,7 +194,7 @@ namespace CppSharp.Passes var method = (Method) expression.Declaration; var expressionSupported = decl.IsValueType && method.Parameters.Count == 0; - if (expression.String.Contains('(')) + if (expression.String.Contains('(') || expression.String.StartsWith("{")) { var argsBuilder = new StringBuilder("new "); argsBuilder.Append(typePrinterResult); diff --git a/tests/CSharp/CSharp.Tests.cs b/tests/CSharp/CSharp.Tests.cs index 6d5829e2..567aa193 100644 --- a/tests/CSharp/CSharp.Tests.cs +++ b/tests/CSharp/CSharp.Tests.cs @@ -255,6 +255,7 @@ public unsafe class CSharpTests : GeneratorTestFixture methodsWithDefaultValues.DefaultDoubleWithoutF(); methodsWithDefaultValues.DefaultIntExpressionWithEnum(); methodsWithDefaultValues.DefaultCtorWithMoreThanOneArg(); + methodsWithDefaultValues.DefaultEmptyBraces(); methodsWithDefaultValues.DefaultWithRefManagedLong(); methodsWithDefaultValues.DefaultWithFunctionCall(); methodsWithDefaultValues.DefaultWithPropertyCall(); diff --git a/tests/CSharp/CSharp.cpp b/tests/CSharp/CSharp.cpp index 26955ff1..02bffc08 100644 --- a/tests/CSharp/CSharp.cpp +++ b/tests/CSharp/CSharp.cpp @@ -693,6 +693,10 @@ void MethodsWithDefaultValues::defaultCtorWithMoreThanOneArg(QMargins m) { } +void MethodsWithDefaultValues::defaultEmptyBraces(Foo foo) +{ +} + void MethodsWithDefaultValues::defaultWithComplexArgs(const QRect& rectangle) { } diff --git a/tests/CSharp/CSharp.h b/tests/CSharp/CSharp.h index 5dd81f57..dc266977 100644 --- a/tests/CSharp/CSharp.h +++ b/tests/CSharp/CSharp.h @@ -439,6 +439,7 @@ public: void defaultDoubleWithoutF(double d1 = 1.0, double d2 = 1.); void defaultIntExpressionWithEnum(int i = Qt::GlobalColor::black + 1); void defaultCtorWithMoreThanOneArg(QMargins m = QMargins(0, 0, 0, 0)); + void defaultEmptyBraces(Foo foo = {}); void defaultWithComplexArgs(const QRect& rectangle = QRect(QPoint(0, 0), QSize(-1, -1))); void defaultWithRefManagedLong(long long* i = 0); void defaultWithFunctionCall(int f = Foo::makeFunctionCall());