Browse Source

Fixed ambiguous code when a nested type and a property-like method with overloads have the same name

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1185/head
Dimitar Dobrev 6 years ago
parent
commit
86a1fbe4da
  1. 5
      src/Generator/Passes/GetterSetterToPropertyPass.cs
  2. 2
      tests/CSharp/CSharp.Tests.cs
  3. 35
      tests/Common/Common.Tests.cs
  4. 10
      tests/Common/Common.cpp
  5. 9
      tests/Common/Common.h

5
src/Generator/Passes/GetterSetterToPropertyPass.cs

@ -38,7 +38,10 @@ namespace CppSharp.Passes @@ -38,7 +38,10 @@ namespace CppSharp.Passes
foreach (Method getter in
from getter in getters
where getter.IsGenerated &&
getter.SynthKind != FunctionSynthKind.ComplementOperator
getter.SynthKind != FunctionSynthKind.ComplementOperator &&
((Class) getter.Namespace).Methods.All(
m => m == getter || !m.IsGenerated || m.Name != getter.Name ||
m.Parameters.Count(p => p.Kind == ParameterKind.Regular) == 0)
select getter)
{
// Make it a read-only property

2
tests/CSharp/CSharp.Tests.cs

@ -1265,6 +1265,6 @@ public unsafe class CSharpTests : GeneratorTestFixture @@ -1265,6 +1265,6 @@ public unsafe class CSharpTests : GeneratorTestFixture
private class OverrideVirtualTemplate : VirtualTemplate<int>
{
public override int Function => 10;
public override int Function() => 10;
}
}

35
tests/Common/Common.Tests.cs

@ -480,25 +480,30 @@ public class CommonTests : GeneratorTestFixture @@ -480,25 +480,30 @@ public class CommonTests : GeneratorTestFixture
public void TestProperties()
{
// Test field property
var prop = new TestProperties();
Assert.That(prop.Field, Is.EqualTo(0));
prop.Field = 10;
Assert.That(prop.Field, Is.EqualTo(10));
using (var prop = new TestProperties())
{
Assert.That(prop.Field, Is.EqualTo(0));
prop.Field = 10;
Assert.That(prop.Field, Is.EqualTo(10));
// Test getter/setter property
prop.Field = 20;
Assert.That(prop.FieldValue, Is.EqualTo(20));
prop.FieldValue = 10;
Assert.That(prop.FieldValue, Is.EqualTo(10));
// Test getter/setter property
prop.Field = 20;
Assert.That(prop.FieldValue, Is.EqualTo(20));
prop.FieldValue = 10;
Assert.That(prop.FieldValue, Is.EqualTo(10));
prop.GetterAndSetterWithTheSameName = 25;
Assert.That(prop.GetterAndSetterWithTheSameName, Is.EqualTo(25));
prop.GetterAndSetterWithTheSameName = 25;
Assert.That(prop.GetterAndSetterWithTheSameName, Is.EqualTo(25));
prop.SetterReturnsBoolean = 35;
Assert.That(prop.SetterReturnsBoolean, Is.EqualTo(35));
prop.SetterReturnsBoolean = 35;
Assert.That(prop.SetterReturnsBoolean, Is.EqualTo(35));
prop.VirtualSetterReturnsBoolean = 45;
Assert.That(prop.VirtualSetterReturnsBoolean, Is.EqualTo(45));
prop.VirtualSetterReturnsBoolean = 45;
Assert.That(prop.VirtualSetterReturnsBoolean, Is.EqualTo(45));
Assert.That(prop.nestedEnum(), Is.EqualTo(5));
Assert.That(prop.nestedEnum(55), Is.EqualTo(55));
}
}
[Test]

10
tests/Common/Common.cpp

@ -586,6 +586,16 @@ bool TestProperties::setVirtualSetterReturnsBoolean(int value) @@ -586,6 +586,16 @@ bool TestProperties::setVirtualSetterReturnsBoolean(int value)
return changed;
}
int TestProperties::nestedEnum()
{
return 5;
}
int TestProperties::nestedEnum(int i)
{
return i;
}
HasOverridenSetter::HasOverridenSetter()
{
}

9
tests/Common/Common.h

@ -578,6 +578,12 @@ DLL_API int Function() @@ -578,6 +578,12 @@ DLL_API int Function()
struct DLL_API TestProperties
{
public:
enum class NestedEnum
{
Value1,
Value2
};
TestProperties();
int Field;
@ -600,6 +606,9 @@ public: @@ -600,6 +606,9 @@ public:
virtual int virtualSetterReturnsBoolean();
virtual bool setVirtualSetterReturnsBoolean(int value);
int nestedEnum();
int nestedEnum(int i);
private:
int FieldValue;
double _refToPrimitiveInSetter;

Loading…
Cancel
Save