From f5cf03144adae8279243cdedc37bf662f7d3755e Mon Sep 17 00:00:00 2001 From: Ruben Tytgat Date: Fri, 26 Jul 2024 13:47:13 +0200 Subject: [PATCH 1/4] Fixes issue #1283 --- src/Generator/Passes/GetterSetterToPropertyPass.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Generator/Passes/GetterSetterToPropertyPass.cs b/src/Generator/Passes/GetterSetterToPropertyPass.cs index 4d49a4a4a..6de31147e 100644 --- a/src/Generator/Passes/GetterSetterToPropertyPass.cs +++ b/src/Generator/Passes/GetterSetterToPropertyPass.cs @@ -40,7 +40,7 @@ private static Stream GetResourceStream(Assembly assembly) } public GetterSetterToPropertyPass() - => VisitOptions.ResetFlags(VisitFlags.ClassTemplateSpecializations); + => VisitOptions.ResetFlags(VisitFlags.ClassBases | VisitFlags.ClassTemplateSpecializations); public override bool VisitClassDecl(Class @class) { From 7ead06e1a64685493d553944902895410ba9f19f Mon Sep 17 00:00:00 2001 From: Ruben Tytgat Date: Fri, 26 Jul 2024 14:42:47 +0200 Subject: [PATCH 2/4] Add test for issue #1283 --- src/Generator.Tests/Passes/TestPasses.cs | 11 +++++++++++ tests/dotnet/Native/Passes.h | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Generator.Tests/Passes/TestPasses.cs b/src/Generator.Tests/Passes/TestPasses.cs index bc3e145ec..a09d1c14d 100644 --- a/src/Generator.Tests/Passes/TestPasses.cs +++ b/src/Generator.Tests/Passes/TestPasses.cs @@ -452,6 +452,17 @@ public void TestFlattenAnonymousTypesToFields() Assert.AreEqual(AccessSpecifier.Protected, @protected.Access); } + [Test] + public void TestGetterSetterToPropertyPassHandlesBaseClassesFirst() + { + var @class = AstContext.Class("TestOverridingVirtualPropertyInNamespacedClass"); + + passBuilder.AddPass(new GetterSetterToPropertyPass()); + passBuilder.RunPasses(pass => pass.VisitASTContext(AstContext)); + + Assert.IsNotEmpty(@class.Properties); + } + private PassBuilder passBuilder; } } diff --git a/tests/dotnet/Native/Passes.h b/tests/dotnet/Native/Passes.h index be83d5236..6d8b51f58 100644 --- a/tests/dotnet/Native/Passes.h +++ b/tests/dotnet/Native/Passes.h @@ -141,3 +141,16 @@ class TestExtractInterfacePass public: void DoSomething(); }; + +// https://github.com/mono/CppSharp/issues/1283 +namespace NamespaceWithVirtualPropertyClass { + class TestNamespacedClassWithVirtualProperty { + public: + virtual int property(); + }; +} + +class TestOverridingVirtualPropertyInNamespacedClass : public NamespaceWithVirtualPropertyClass::TestNamespacedClassWithVirtualProperty { +public: + virtual int property() override; +}; From e953ea2c2b110a2b1e5dfb82c067bb3c6477660d Mon Sep 17 00:00:00 2001 From: Ruben Tytgat Date: Fri, 26 Jul 2024 15:31:00 +0200 Subject: [PATCH 3/4] Move test for issue #1283 to CSharp test suite --- src/Generator.Tests/Passes/TestPasses.cs | 11 ----------- tests/dotnet/CSharp/CSharp.cpp | 5 +++++ tests/dotnet/CSharp/CSharp.h | 13 +++++++++++++ tests/dotnet/Native/Passes.h | 13 ------------- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/Generator.Tests/Passes/TestPasses.cs b/src/Generator.Tests/Passes/TestPasses.cs index a09d1c14d..bc3e145ec 100644 --- a/src/Generator.Tests/Passes/TestPasses.cs +++ b/src/Generator.Tests/Passes/TestPasses.cs @@ -452,17 +452,6 @@ public void TestFlattenAnonymousTypesToFields() Assert.AreEqual(AccessSpecifier.Protected, @protected.Access); } - [Test] - public void TestGetterSetterToPropertyPassHandlesBaseClassesFirst() - { - var @class = AstContext.Class("TestOverridingVirtualPropertyInNamespacedClass"); - - passBuilder.AddPass(new GetterSetterToPropertyPass()); - passBuilder.RunPasses(pass => pass.VisitASTContext(AstContext)); - - Assert.IsNotEmpty(@class.Properties); - } - private PassBuilder passBuilder; } } diff --git a/tests/dotnet/CSharp/CSharp.cpp b/tests/dotnet/CSharp/CSharp.cpp index 9a8beb618..4d8fd04b8 100644 --- a/tests/dotnet/CSharp/CSharp.cpp +++ b/tests/dotnet/CSharp/CSharp.cpp @@ -1282,6 +1282,11 @@ int HasConflictWithAbstractProperty::conflictWithProperty() return 0; } +int TestOverrideOfPropertyInNamespacedClass::property() +{ + return 0; +} + const char* HasVirtualTakesReturnsProblematicTypes::virtualTakesAndReturnsString(const char* c) { return c; diff --git a/tests/dotnet/CSharp/CSharp.h b/tests/dotnet/CSharp/CSharp.h index 885244693..2b0d1c36a 100644 --- a/tests/dotnet/CSharp/CSharp.h +++ b/tests/dotnet/CSharp/CSharp.h @@ -1029,6 +1029,19 @@ class DLL_API HasConflictWithAbstractProperty virtual int getConflictWithProperty() = 0; }; +// https://github.com/mono/CppSharp/issues/1283 +namespace NamespaceWithVirtualPropertyClass { + class DLL_API HasOverridenPropertyInNamespacedClass { + public: + virtual int property() = 0; + }; +} + +class DLL_API TestOverrideOfPropertyInNamespacedClass : public NamespaceWithVirtualPropertyClass::HasOverridenPropertyInNamespacedClass { +public: + virtual int property() override; +}; + template class lowerCase { diff --git a/tests/dotnet/Native/Passes.h b/tests/dotnet/Native/Passes.h index 6d8b51f58..be83d5236 100644 --- a/tests/dotnet/Native/Passes.h +++ b/tests/dotnet/Native/Passes.h @@ -141,16 +141,3 @@ class TestExtractInterfacePass public: void DoSomething(); }; - -// https://github.com/mono/CppSharp/issues/1283 -namespace NamespaceWithVirtualPropertyClass { - class TestNamespacedClassWithVirtualProperty { - public: - virtual int property(); - }; -} - -class TestOverridingVirtualPropertyInNamespacedClass : public NamespaceWithVirtualPropertyClass::TestNamespacedClassWithVirtualProperty { -public: - virtual int property() override; -}; From 0cc04c3b36af787c7f132fe9495ae5b6895fe4c9 Mon Sep 17 00:00:00 2001 From: Ruben Tytgat Date: Fri, 26 Jul 2024 16:07:36 +0200 Subject: [PATCH 4/4] Fix typo --- tests/dotnet/CSharp/CSharp.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/dotnet/CSharp/CSharp.h b/tests/dotnet/CSharp/CSharp.h index 2b0d1c36a..bc61b21ba 100644 --- a/tests/dotnet/CSharp/CSharp.h +++ b/tests/dotnet/CSharp/CSharp.h @@ -1031,13 +1031,13 @@ class DLL_API HasConflictWithAbstractProperty // https://github.com/mono/CppSharp/issues/1283 namespace NamespaceWithVirtualPropertyClass { - class DLL_API HasOverridenPropertyInNamespacedClass { + class DLL_API HasOverriddenPropertyInNamespacedClass { public: virtual int property() = 0; }; } -class DLL_API TestOverrideOfPropertyInNamespacedClass : public NamespaceWithVirtualPropertyClass::HasOverridenPropertyInNamespacedClass { +class DLL_API TestOverrideOfPropertyInNamespacedClass : public NamespaceWithVirtualPropertyClass::HasOverriddenPropertyInNamespacedClass { public: virtual int property() override; };