Browse Source

Fix regressed virtual read-only properties with setters in subclasses

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1261/head
Dimitar Dobrev 6 years ago
parent
commit
e11057d71d
  1. 54
      src/Generator/Passes/GetterSetterToPropertyPass.cs
  2. 7
      tests/Common/Common.Tests.cs
  3. 14
      tests/Common/Common.cpp
  4. 5
      tests/Common/Common.h

54
src/Generator/Passes/GetterSetterToPropertyPass.cs

@ -143,8 +143,34 @@ namespace CppSharp.Passes @@ -143,8 +143,34 @@ namespace CppSharp.Passes
{
foreach (var property in newProperties)
{
if (property.IsOverride)
ProcessOverridden(@class, property);
if (property.GetMethod == null)
{
if (property.SetMethod != null)
property.SetMethod.GenerationKind = GenerationKind.Generate;
@class.Properties.Remove(property);
continue;
}
if (property.SetMethod == null &&
@class.GetOverloads(property.GetMethod).Any(
m => m != property.GetMethod && !m.Ignore))
{
property.GetMethod.GenerationKind = GenerationKind.Generate;
@class.Properties.Remove(property);
continue;
}
RenameConflictingMethods(@class, property);
CombineComments(property);
}
}
private static void ProcessOverridden(Class @class, Property property)
{
if (!property.IsOverride)
return;
Property baseProperty = GetBaseProperty(@class, property);
if (baseProperty == null)
{
@ -161,27 +187,11 @@ namespace CppSharp.Passes @@ -161,27 +187,11 @@ namespace CppSharp.Passes
}
else if (property.GetMethod == null && baseProperty.SetMethod != null)
property.GetMethod = baseProperty.GetMethod;
else if (property.SetMethod == null)
property.SetMethod = baseProperty.SetMethod;
}
if (property.GetMethod == null)
else if (property.SetMethod == null || baseProperty.SetMethod == null)
{
if (property.SetMethod != null)
property.SetMethod.GenerationKind = GenerationKind.Generate;
@class.Properties.Remove(property);
continue;
}
if (property.SetMethod == null &&
@class.GetOverloads(property.GetMethod).Any(
m => m != property.GetMethod && !m.Ignore))
{
property.GetMethod.GenerationKind = GenerationKind.Generate;
@class.Properties.Remove(property);
continue;
}
RenameConflictingMethods(@class, property);
CombineComments(property);
property.SetMethod = baseProperty.SetMethod;
}
}
@ -191,8 +201,10 @@ namespace CppSharp.Passes @@ -191,8 +201,10 @@ namespace CppSharp.Passes
{
Class baseClass = @base.Class.OriginalClass ?? @base.Class;
Property baseProperty = baseClass.Properties.Find(p =>
(@override.GetMethod != null && @override.GetMethod.BaseMethod == p.GetMethod) ||
(@override.SetMethod != null && @override.SetMethod.BaseMethod == p.SetMethod) ||
(@override.GetMethod?.IsOverride == true &&
@override.GetMethod.BaseMethod == p.GetMethod) ||
(@override.SetMethod?.IsOverride == true &&
@override.SetMethod.BaseMethod == p.SetMethod) ||
(@override.Field != null && @override.Field == p.Field));
if (baseProperty != null)
return baseProperty;

7
tests/Common/Common.Tests.cs

@ -522,6 +522,13 @@ public class CommonTests : GeneratorTestFixture @@ -522,6 +522,13 @@ public class CommonTests : GeneratorTestFixture
Assert.That(prop.Get32Bit, Is.EqualTo(10));
Assert.That(prop.IsEmpty, Is.EqualTo(prop.Empty));
Assert.That(prop.VirtualGetter, Is.EqualTo(15));
}
using (var prop = new HasOverridenSetter())
{
Assert.That(prop.VirtualGetter, Is.EqualTo(20));
prop.SetVirtualGetter(5);
}
}

14
tests/Common/Common.cpp

@ -628,6 +628,11 @@ bool TestProperties::empty() @@ -628,6 +628,11 @@ bool TestProperties::empty()
return false;
}
int TestProperties::virtualGetter()
{
return 15;
}
HasOverridenSetter::HasOverridenSetter()
{
}
@ -646,6 +651,15 @@ bool HasOverridenSetter::setVirtualSetterReturnsBoolean(int value) @@ -646,6 +651,15 @@ bool HasOverridenSetter::setVirtualSetterReturnsBoolean(int value)
return TestProperties::setVirtualSetterReturnsBoolean(value);
}
int HasOverridenSetter::virtualGetter()
{
return 20;
}
void HasOverridenSetter::setVirtualGetter(int value)
{
}
TypeMappedIndex::TypeMappedIndex()
{
}

5
tests/Common/Common.h

@ -614,6 +614,8 @@ public: @@ -614,6 +614,8 @@ public:
int get32Bit();
bool isEmpty();
bool empty();
virtual int virtualGetter();
private:
int FieldValue;
double _refToPrimitiveInSetter;
@ -630,6 +632,9 @@ public: @@ -630,6 +632,9 @@ public:
int virtualSetterReturnsBoolean() override;
bool setVirtualSetterReturnsBoolean(int value) override;
int virtualGetter() override;
void setVirtualGetter(int value);
};
class DLL_API TypeMappedIndex

Loading…
Cancel
Save