From 347d0cdbaf7fa9d93d29d5f2306825c8f32d03c2 Mon Sep 17 00:00:00 2001 From: Abhinav Tripathi Date: Wed, 30 Dec 2015 18:08:01 +0530 Subject: [PATCH] Fix for fn call when def argument is interface. --- .../Generators/CSharp/CSharpTextTemplate.cs | 12 +++++++++++- tests/CSharp/CSharp.cpp | 8 ++++++++ tests/CSharp/CSharp.h | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index 00ca1b7f..b88e9bf6 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -2202,9 +2202,11 @@ namespace CppSharp.Generators.CSharp 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) @@ -2221,6 +2223,14 @@ namespace CppSharp.Generators.CSharp 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); diff --git a/tests/CSharp/CSharp.cpp b/tests/CSharp/CSharp.cpp index 4e38191a..5d10bb52 100644 --- a/tests/CSharp/CSharp.cpp +++ b/tests/CSharp/CSharp.cpp @@ -143,6 +143,10 @@ Bar::Bar(Qux qux) { } +Bar::Bar(Items item) +{ +} + int Bar::method() { return 2; @@ -471,6 +475,10 @@ void MethodsWithDefaultValues::defaultImplicitCtorEnum(Baz arg) { } +void MethodsWithDefaultValues::defaultImplicitCtorEnumTwo(Bar arg) +{ +} + void MethodsWithDefaultValues::defaultIntWithLongExpression(unsigned int i) { } diff --git a/tests/CSharp/CSharp.h b/tests/CSharp/CSharp.h index cae8b167..b7f14836 100644 --- a/tests/CSharp/CSharp.h +++ b/tests/CSharp/CSharp.h @@ -63,6 +63,7 @@ public: }; Bar(); Bar(Qux qux); + Bar(Items item); int method(); const Foo& operator[](int i) const; Foo& operator[](int i); @@ -364,6 +365,7 @@ public: // 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);