Skip to content

Commit c688330

Browse files
committed
Fixed the generated C# for parameters initialized with {}.
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent c51b3cb commit c688330

File tree

4 files changed

+7
-1
lines changed

4 files changed

+7
-1
lines changed

src/Generator/Passes/HandleDefaultParamValuesPass.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private bool CheckForDefaultPointer(Type desugared, ref string result)
194194
var method = (Method) expression.Declaration;
195195
var expressionSupported = decl.IsValueType && method.Parameters.Count == 0;
196196

197-
if (expression.String.Contains('('))
197+
if (expression.String.Contains('(') || expression.String.StartsWith("{"))
198198
{
199199
var argsBuilder = new StringBuilder("new ");
200200
argsBuilder.Append(typePrinterResult);

tests/CSharp/CSharp.Tests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ public void TestDefaultArguments()
255255
methodsWithDefaultValues.DefaultDoubleWithoutF();
256256
methodsWithDefaultValues.DefaultIntExpressionWithEnum();
257257
methodsWithDefaultValues.DefaultCtorWithMoreThanOneArg();
258+
methodsWithDefaultValues.DefaultEmptyBraces();
258259
methodsWithDefaultValues.DefaultWithRefManagedLong();
259260
methodsWithDefaultValues.DefaultWithFunctionCall();
260261
methodsWithDefaultValues.DefaultWithPropertyCall();

tests/CSharp/CSharp.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,10 @@ void MethodsWithDefaultValues::defaultCtorWithMoreThanOneArg(QMargins m)
693693
{
694694
}
695695

696+
void MethodsWithDefaultValues::defaultEmptyBraces(Foo foo)
697+
{
698+
}
699+
696700
void MethodsWithDefaultValues::defaultWithComplexArgs(const QRect& rectangle)
697701
{
698702
}

tests/CSharp/CSharp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ class DLL_API MethodsWithDefaultValues : public Quux
439439
void defaultDoubleWithoutF(double d1 = 1.0, double d2 = 1.);
440440
void defaultIntExpressionWithEnum(int i = Qt::GlobalColor::black + 1);
441441
void defaultCtorWithMoreThanOneArg(QMargins m = QMargins(0, 0, 0, 0));
442+
void defaultEmptyBraces(Foo foo = {});
442443
void defaultWithComplexArgs(const QRect& rectangle = QRect(QPoint(0, 0), QSize(-1, -1)));
443444
void defaultWithRefManagedLong(long long* i = 0);
444445
void defaultWithFunctionCall(int f = Foo::makeFunctionCall());

0 commit comments

Comments
 (0)