Browse Source

Fixed the generated C# code when a default arg with an ignored expression is preceded by another default arg.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/681/head
Dimitar Dobrev 9 years ago
parent
commit
0837094d76
  1. 4
      src/Generator/Passes/HandleDefaultParamValuesPass.cs
  2. 2
      tests/CSharp/CSharp.Tests.cs
  3. 2
      tests/CSharp/CSharp.cpp
  4. 2
      tests/CSharp/CSharp.h

4
src/Generator/Passes/HandleDefaultParamValuesPass.cs

@ -48,7 +48,11 @@ namespace CppSharp.Passes @@ -48,7 +48,11 @@ namespace CppSharp.Passes
if (PrintExpression(parameter.Type, parameter.DefaultArgument, ref result) == null)
overloadIndices.Add(function.Parameters.IndexOf(parameter));
if (string.IsNullOrEmpty(result))
{
parameter.DefaultArgument = null;
foreach (var p in function.Parameters.TakeWhile(p => p != parameter))
p.DefaultArgument = null;
}
else
parameter.DefaultArgument.String = result;
}

2
tests/CSharp/CSharp.Tests.cs

@ -216,7 +216,7 @@ public unsafe class CSharpTests : GeneratorTestFixture @@ -216,7 +216,7 @@ public unsafe class CSharpTests : GeneratorTestFixture
methodsWithDefaultValues.DefaultWithEnumInLowerCasedNameSpace();
methodsWithDefaultValues.DefaultWithCharFromInt();
methodsWithDefaultValues.DefaultWithFreeConstantInNameSpace();
methodsWithDefaultValues.DefaultWithStdNumericLimits(5);
methodsWithDefaultValues.DefaultWithStdNumericLimits(10, 5);
}
}

2
tests/CSharp/CSharp.cpp

@ -591,7 +591,7 @@ void MethodsWithDefaultValues::defaultWithFreeConstantInNameSpace(int c) @@ -591,7 +591,7 @@ void MethodsWithDefaultValues::defaultWithFreeConstantInNameSpace(int c)
{
}
void MethodsWithDefaultValues::defaultWithStdNumericLimits(int i)
void MethodsWithDefaultValues::defaultWithStdNumericLimits(double d, int i)
{
}

2
tests/CSharp/CSharp.h

@ -414,7 +414,7 @@ public: @@ -414,7 +414,7 @@ public:
void defaultWithEnumInLowerCasedNameSpace(lowerCaseNameSpace::Enum e = lowerCaseNameSpace::Enum::Item2);
void defaultWithCharFromInt(char c = 32);
void defaultWithFreeConstantInNameSpace(int c = HasFreeConstant::FREE_CONSTANT_IN_NAMESPACE);
void defaultWithStdNumericLimits(int i = std::numeric_limits<double>::infinity());
void defaultWithStdNumericLimits(double d = 1.0, int i = std::numeric_limits<double>::infinity());
int getA();
private:
Foo m_foo;

Loading…
Cancel
Save