Skip to content

Commit dd1576b

Browse files
committed
Merge pull request #600 from genuinelucifer/defValCall
Fix for fn call when def argument is interface.
2 parents 1471e6f + 347d0cd commit dd1576b

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/Generator/Generators/CSharp/CSharpTextTemplate.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -2202,9 +2202,11 @@ public void GenerateMethod(Method method, Class @class)
22022202

22032203
private string OverloadParamNameWithDefValue(Parameter p, ref int index)
22042204
{
2205+
Class @class;
22052206
return p.Type.IsPointerToPrimitiveType() && p.Usage == ParameterUsage.InOut && p.HasDefaultValue
22062207
? "ref param" + index++
2207-
: ExpressionPrinter.VisitExpression(p.DefaultArgument).Value;
2208+
: (( p.Type.TryGetClass(out @class) && @class.IsInterface) ? "param" + index++
2209+
: ExpressionPrinter.VisitExpression(p.DefaultArgument).Value);
22082210
}
22092211

22102212
private void GenerateOverloadCall(Function function)
@@ -2221,6 +2223,14 @@ private void GenerateOverloadCall(Function function)
22212223
WriteLine("{0} param{1} = {2};", pointeeType, j++,
22222224
primitiveType == PrimitiveType.Bool ? "false" : "0");
22232225
}
2226+
Class @class;
2227+
if (parameter.Kind == ParameterKind.Regular && parameter.Ignore &&
2228+
parameter.Type.Desugar().TryGetClass(out @class) && @class.IsInterface &&
2229+
parameter.HasDefaultValue)
2230+
{
2231+
WriteLine("var param{0} = ({1}) {2};", j++, @class.OriginalClass.OriginalName,
2232+
ExpressionPrinter.VisitExpression(parameter.DefaultArgument).Value);
2233+
}
22242234
}
22252235

22262236
GenerateManagedCall(function);

tests/CSharp/CSharp.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ Bar::Bar(Qux qux)
143143
{
144144
}
145145

146+
Bar::Bar(Items item)
147+
{
148+
}
149+
146150
int Bar::method()
147151
{
148152
return 2;
@@ -471,6 +475,10 @@ void MethodsWithDefaultValues::defaultImplicitCtorEnum(Baz arg)
471475
{
472476
}
473477

478+
void MethodsWithDefaultValues::defaultImplicitCtorEnumTwo(Bar arg)
479+
{
480+
}
481+
474482
void MethodsWithDefaultValues::defaultIntWithLongExpression(unsigned int i)
475483
{
476484
}

tests/CSharp/CSharp.h

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class DLL_API Bar : public Qux
6363
};
6464
Bar();
6565
Bar(Qux qux);
66+
Bar(Items item);
6667
int method();
6768
const Foo& operator[](int i) const;
6869
Foo& operator[](int i);
@@ -364,6 +365,7 @@ class DLL_API MethodsWithDefaultValues : public Quux
364365
// in this case the arg is a MaterializeTemporaryExpr, in the other not
365366
// I cannot see the difference but it's there so we need both tests
366367
void defaultImplicitCtorEnum(Baz arg = Bar::Item1);
368+
void defaultImplicitCtorEnumTwo(Bar arg = Bar::Items::Item1);
367369
void defaultIntWithLongExpression(unsigned int i = DEFAULT_INT);
368370
void defaultRefTypeEnumImplicitCtor(const QColor &fillColor = Qt::white);
369371
void rotate4x4Matrix(float angle, float x, float y, float z = 0.0f);

0 commit comments

Comments
 (0)