From 40ca6f281aab6806927c5981e75a6422ec78a639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Matos?= Date: Mon, 16 Mar 2020 21:13:25 +0000 Subject: [PATCH] Fix bug related to processing of potential property methods. Fixes https://github.com/mono/CppSharp/issues/1291. --- src/Generator/Passes/GetterSetterToPropertyPass.cs | 3 ++- tests/Common/Common.Tests.cs | 4 ++++ tests/Common/Common.cpp | 14 ++++++++++++++ tests/Common/Common.h | 5 +++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Generator/Passes/GetterSetterToPropertyPass.cs b/src/Generator/Passes/GetterSetterToPropertyPass.cs index 50ddccb3..aa1b74ec 100644 --- a/src/Generator/Passes/GetterSetterToPropertyPass.cs +++ b/src/Generator/Passes/GetterSetterToPropertyPass.cs @@ -303,7 +303,8 @@ namespace CppSharp.Passes private static string GetPropertyName(string name) { var firstWord = GetFirstWord(name); - if (Match(firstWord, new[] { "get" }) && name != firstWord && + if (Match(firstWord, new[] { "get" }) && + (string.Compare(name, firstWord, StringComparison.InvariantCultureIgnoreCase) != 0) && !char.IsNumber(name[3])) { if (char.IsLower(name[0])) diff --git a/tests/Common/Common.Tests.cs b/tests/Common/Common.Tests.cs index c0687da2..984fd6af 100644 --- a/tests/Common/Common.Tests.cs +++ b/tests/Common/Common.Tests.cs @@ -450,6 +450,10 @@ public class CommonTests : GeneratorTestFixture Assert.AreEqual(4, newProperties.Field); newProperties.Field = 5; Assert.AreEqual(5, indexedProperties[(byte) 0].Field); + newProperties.get(); + newProperties.set(0); + newProperties.Get(); + newProperties.Set(0); var bar = new Bar { A = 5 }; indexedProperties[0u] = bar; diff --git a/tests/Common/Common.cpp b/tests/Common/Common.cpp index d47a873b..a5924342 100644 --- a/tests/Common/Common.cpp +++ b/tests/Common/Common.cpp @@ -591,10 +591,24 @@ void TestProperties::getterAndSetterWithTheSameName(int value) _getterAndSetterWithTheSameName = value; } +int TestProperties::get() const +{ + return 3; +} + void TestProperties::set(int value) { } +int TestProperties::Get() const +{ + return 3; +} + +void TestProperties::Set(int value) +{ +} + int TestProperties::setterReturnsBoolean() { return _setterReturnsBoolean; diff --git a/tests/Common/Common.h b/tests/Common/Common.h index e7817117..437cab07 100644 --- a/tests/Common/Common.h +++ b/tests/Common/Common.h @@ -605,6 +605,10 @@ public: int getterAndSetterWithTheSameName(); void getterAndSetterWithTheSameName(int value); + int Get() const; + void Set(int value); + + int get() const; void set(int value); int setterReturnsBoolean(); @@ -630,6 +634,7 @@ public: bool contains(char c); bool contains(const char* str); + private: int FieldValue; double _refToPrimitiveInSetter;