From 45e4ba778270a49f89405b8f4896ee12b6d755d5 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Mon, 6 Jul 2015 21:43:13 +0300 Subject: [PATCH] Fixed a compilation error when having a setter match for an explicit interface getter. Signed-off-by: Dimitar Dobrev --- .../GetterSetterToPropertyAdvancedPass.cs | 20 ++++++++-------- tests/CSharpTemp/CSharpTemp.Tests.cs | 23 +++++++++++-------- tests/CSharpTemp/CSharpTemp.cpp | 4 ++++ tests/CSharpTemp/CSharpTemp.h | 1 + 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs b/src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs index 2b09bbf5..7aed15f9 100644 --- a/src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs +++ b/src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs @@ -55,7 +55,9 @@ namespace CppSharp.Passes if (char.IsLower(setter.Name[0])) nameBuilder[0] = char.ToLowerInvariant(nameBuilder[0]); 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); if (name == afterSet && @@ -82,11 +84,11 @@ namespace CppSharp.Passes goto next; } } - Property baseVirtualProperty = type.GetRootBaseProperty(new Property { Name = afterSet }); - if (!type.IsInterface && baseVirtualProperty != null) + Property baseProperty = type.GetRootBaseProperty(new Property { Name = afterSet }); + if (!type.IsInterface && baseProperty != null && baseProperty.IsVirtual && setter.IsVirtual) { - bool isReadOnly = baseVirtualProperty.SetMethod == null; - GenerateProperty(setter.Namespace, baseVirtualProperty.GetMethod, + bool isReadOnly = baseProperty.SetMethod == null; + GenerateProperty(setter.Namespace, baseProperty.GetMethod, readOnly || isReadOnly ? null : setter); } next: @@ -96,14 +98,14 @@ namespace CppSharp.Passes { Class type = (Class) nonSetter.Namespace; string name = GetPropertyName(nonSetter.Name); - Property baseVirtualProperty = type.GetRootBaseProperty(new Property { Name = name }); - if (!type.IsInterface && baseVirtualProperty != null) + Property baseProperty = type.GetRootBaseProperty(new Property { Name = name }); + if (!type.IsInterface && baseProperty != null && baseProperty.IsVirtual) { - bool isReadOnly = baseVirtualProperty.SetMethod == null; + bool isReadOnly = baseProperty.SetMethod == null; if (readOnly == isReadOnly) { GenerateProperty(nonSetter.Namespace, nonSetter, - readOnly ? null : baseVirtualProperty.SetMethod); + readOnly ? null : baseProperty.SetMethod); } } } diff --git a/tests/CSharpTemp/CSharpTemp.Tests.cs b/tests/CSharpTemp/CSharpTemp.Tests.cs index c8c555d0..c40b5f2f 100644 --- a/tests/CSharpTemp/CSharpTemp.Tests.cs +++ b/tests/CSharpTemp/CSharpTemp.Tests.cs @@ -50,16 +50,19 @@ public class CSharpTempTests : GeneratorTestFixture [Test] public void TestMultipleInheritance() { - var baz = new Baz(); - Assert.That(baz.Method, Is.EqualTo(1)); - var bar = (IBar) baz; - Assert.That(bar.Method, Is.EqualTo(2)); - Assert.That(baz[0], Is.EqualTo(50)); - bar[0] = new Foo { A = 1000 }; - Assert.That(bar[0].A, Is.EqualTo(1000)); - Assert.That(baz.FarAwayFunc, Is.EqualTo(20)); - Assert.That(baz.TakesQux(baz), Is.EqualTo(20)); - Assert.That(baz.ReturnQux().FarAwayFunc, Is.EqualTo(20)); + using (var baz = new Baz()) + { + Assert.That(baz.Method, Is.EqualTo(1)); + var bar = (IBar) baz; + Assert.That(bar.Method, Is.EqualTo(2)); + Assert.That(baz[0], Is.EqualTo(50)); + bar[0] = new Foo { A = 1000 }; + Assert.That(bar[0].A, Is.EqualTo(1000)); + Assert.That(baz.FarAwayFunc, Is.EqualTo(20)); + Assert.That(baz.TakesQux(baz), Is.EqualTo(20)); + Assert.That(baz.ReturnQux().FarAwayFunc, Is.EqualTo(20)); + baz.SetMethod(1); + } } [Test] diff --git a/tests/CSharpTemp/CSharpTemp.cpp b/tests/CSharpTemp/CSharpTemp.cpp index 09d12abd..3cfa9751 100644 --- a/tests/CSharpTemp/CSharpTemp.cpp +++ b/tests/CSharpTemp/CSharpTemp.cpp @@ -137,6 +137,10 @@ Qux Baz::returnQux() return Qux(); } +void Baz::setMethod(int value) +{ +} + int AbstractProprietor::getValue() { return m_value; diff --git a/tests/CSharpTemp/CSharpTemp.h b/tests/CSharpTemp/CSharpTemp.h index 98448aec..690e61c4 100644 --- a/tests/CSharpTemp/CSharpTemp.h +++ b/tests/CSharpTemp/CSharpTemp.h @@ -83,6 +83,7 @@ public: int takesQux(const Qux& qux); Qux returnQux(); + void setMethod(int value); typedef bool (*FunctionTypedef)(const void *); FunctionTypedef functionTypedef;