Browse Source

Fixed a compilation error when having a setter match for an explicit interface getter.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/513/head
Dimitar Dobrev 10 years ago
parent
commit
45e4ba7782
  1. 20
      src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs
  2. 23
      tests/CSharpTemp/CSharpTemp.Tests.cs
  3. 4
      tests/CSharpTemp/CSharpTemp.cpp
  4. 1
      tests/CSharpTemp/CSharpTemp.h

20
src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs

@ -55,7 +55,9 @@ namespace CppSharp.Passes
if (char.IsLower(setter.Name[0])) if (char.IsLower(setter.Name[0]))
nameBuilder[0] = char.ToLowerInvariant(nameBuilder[0]); nameBuilder[0] = char.ToLowerInvariant(nameBuilder[0]);
string afterSet = nameBuilder.ToString(); string afterSet = nameBuilder.ToString();
foreach (var getter in nonSetters.Where(m => m.Namespace == type)) var s = setter;
foreach (var getter in nonSetters.Where(m => m.Namespace == type &&
m.ExplicitInterfaceImpl == s.ExplicitInterfaceImpl))
{ {
var name = GetReadWritePropertyName(getter, afterSet); var name = GetReadWritePropertyName(getter, afterSet);
if (name == afterSet && if (name == afterSet &&
@ -82,11 +84,11 @@ namespace CppSharp.Passes
goto next; goto next;
} }
} }
Property baseVirtualProperty = type.GetRootBaseProperty(new Property { Name = afterSet }); Property baseProperty = type.GetRootBaseProperty(new Property { Name = afterSet });
if (!type.IsInterface && baseVirtualProperty != null) if (!type.IsInterface && baseProperty != null && baseProperty.IsVirtual && setter.IsVirtual)
{ {
bool isReadOnly = baseVirtualProperty.SetMethod == null; bool isReadOnly = baseProperty.SetMethod == null;
GenerateProperty(setter.Namespace, baseVirtualProperty.GetMethod, GenerateProperty(setter.Namespace, baseProperty.GetMethod,
readOnly || isReadOnly ? null : setter); readOnly || isReadOnly ? null : setter);
} }
next: next:
@ -96,14 +98,14 @@ namespace CppSharp.Passes
{ {
Class type = (Class) nonSetter.Namespace; Class type = (Class) nonSetter.Namespace;
string name = GetPropertyName(nonSetter.Name); string name = GetPropertyName(nonSetter.Name);
Property baseVirtualProperty = type.GetRootBaseProperty(new Property { Name = name }); Property baseProperty = type.GetRootBaseProperty(new Property { Name = name });
if (!type.IsInterface && baseVirtualProperty != null) if (!type.IsInterface && baseProperty != null && baseProperty.IsVirtual)
{ {
bool isReadOnly = baseVirtualProperty.SetMethod == null; bool isReadOnly = baseProperty.SetMethod == null;
if (readOnly == isReadOnly) if (readOnly == isReadOnly)
{ {
GenerateProperty(nonSetter.Namespace, nonSetter, GenerateProperty(nonSetter.Namespace, nonSetter,
readOnly ? null : baseVirtualProperty.SetMethod); readOnly ? null : baseProperty.SetMethod);
} }
} }
} }

23
tests/CSharpTemp/CSharpTemp.Tests.cs

@ -50,16 +50,19 @@ public class CSharpTempTests : GeneratorTestFixture
[Test] [Test]
public void TestMultipleInheritance() public void TestMultipleInheritance()
{ {
var baz = new Baz(); using (var baz = new Baz())
Assert.That(baz.Method, Is.EqualTo(1)); {
var bar = (IBar) baz; Assert.That(baz.Method, Is.EqualTo(1));
Assert.That(bar.Method, Is.EqualTo(2)); var bar = (IBar) baz;
Assert.That(baz[0], Is.EqualTo(50)); Assert.That(bar.Method, Is.EqualTo(2));
bar[0] = new Foo { A = 1000 }; Assert.That(baz[0], Is.EqualTo(50));
Assert.That(bar[0].A, Is.EqualTo(1000)); bar[0] = new Foo { A = 1000 };
Assert.That(baz.FarAwayFunc, Is.EqualTo(20)); Assert.That(bar[0].A, Is.EqualTo(1000));
Assert.That(baz.TakesQux(baz), Is.EqualTo(20)); Assert.That(baz.FarAwayFunc, Is.EqualTo(20));
Assert.That(baz.ReturnQux().FarAwayFunc, Is.EqualTo(20)); Assert.That(baz.TakesQux(baz), Is.EqualTo(20));
Assert.That(baz.ReturnQux().FarAwayFunc, Is.EqualTo(20));
baz.SetMethod(1);
}
} }
[Test] [Test]

4
tests/CSharpTemp/CSharpTemp.cpp

@ -137,6 +137,10 @@ Qux Baz::returnQux()
return Qux(); return Qux();
} }
void Baz::setMethod(int value)
{
}
int AbstractProprietor::getValue() int AbstractProprietor::getValue()
{ {
return m_value; return m_value;

1
tests/CSharpTemp/CSharpTemp.h

@ -83,6 +83,7 @@ public:
int takesQux(const Qux& qux); int takesQux(const Qux& qux);
Qux returnQux(); Qux returnQux();
void setMethod(int value);
typedef bool (*FunctionTypedef)(const void *); typedef bool (*FunctionTypedef)(const void *);
FunctionTypedef functionTypedef; FunctionTypedef functionTypedef;

Loading…
Cancel
Save