Skip to content

Fix for fn call when def argument is interface. #600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Generator/Generators/CSharp/CSharpTextTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2202,9 +2202,11 @@ public void GenerateMethod(Method method, Class @class)

private string OverloadParamNameWithDefValue(Parameter p, ref int index)
{
Class @class;
return p.Type.IsPointerToPrimitiveType() && p.Usage == ParameterUsage.InOut && p.HasDefaultValue
? "ref param" + index++
: ExpressionPrinter.VisitExpression(p.DefaultArgument).Value;
: (( p.Type.TryGetClass(out @class) && @class.IsInterface) ? "param" + index++
: ExpressionPrinter.VisitExpression(p.DefaultArgument).Value);
}

private void GenerateOverloadCall(Function function)
Expand All @@ -2221,6 +2223,14 @@ private void GenerateOverloadCall(Function function)
WriteLine("{0} param{1} = {2};", pointeeType, j++,
primitiveType == PrimitiveType.Bool ? "false" : "0");
}
Class @class;
if (parameter.Kind == ParameterKind.Regular && parameter.Ignore &&
parameter.Type.Desugar().TryGetClass(out @class) && @class.IsInterface &&
parameter.HasDefaultValue)
{
WriteLine("var param{0} = ({1}) {2};", j++, @class.OriginalClass.OriginalName,
ExpressionPrinter.VisitExpression(parameter.DefaultArgument).Value);
}
}

GenerateManagedCall(function);
Expand Down
8 changes: 8 additions & 0 deletions tests/CSharp/CSharp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ Bar::Bar(Qux qux)
{
}

Bar::Bar(Items item)
{
}

int Bar::method()
{
return 2;
Expand Down Expand Up @@ -471,6 +475,10 @@ void MethodsWithDefaultValues::defaultImplicitCtorEnum(Baz arg)
{
}

void MethodsWithDefaultValues::defaultImplicitCtorEnumTwo(Bar arg)
{
}

void MethodsWithDefaultValues::defaultIntWithLongExpression(unsigned int i)
{
}
Expand Down
2 changes: 2 additions & 0 deletions tests/CSharp/CSharp.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class DLL_API Bar : public Qux
};
Bar();
Bar(Qux qux);
Bar(Items item);
int method();
const Foo& operator[](int i) const;
Foo& operator[](int i);
Expand Down Expand Up @@ -364,6 +365,7 @@ class DLL_API MethodsWithDefaultValues : public Quux
// in this case the arg is a MaterializeTemporaryExpr, in the other not
// I cannot see the difference but it's there so we need both tests
void defaultImplicitCtorEnum(Baz arg = Bar::Item1);
void defaultImplicitCtorEnumTwo(Bar arg = Bar::Items::Item1);
void defaultIntWithLongExpression(unsigned int i = DEFAULT_INT);
void defaultRefTypeEnumImplicitCtor(const QColor &fillColor = Qt::white);
void rotate4x4Matrix(float angle, float x, float y, float z = 0.0f);
Expand Down