From 06e4b577e93ae77b2c40476ef3b6bb5ddf439ec7 Mon Sep 17 00:00:00 2001 From: Vipul Cariappa Date: Thu, 7 Aug 2025 14:39:52 +0200 Subject: [PATCH] fix JitCall codegen for duplicate symbols within namespaces --- lib/CppInterOp/CppInterOp.cpp | 2 + .../CppInterOp/FunctionReflectionTest.cpp | 42 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/lib/CppInterOp/CppInterOp.cpp b/lib/CppInterOp/CppInterOp.cpp index 01a14ce03..73d61d0d6 100755 --- a/lib/CppInterOp/CppInterOp.cpp +++ b/lib/CppInterOp/CppInterOp.cpp @@ -1925,6 +1925,7 @@ void get_type_as_string(QualType QT, std::string& type_name, ASTContext& C, Policy.SuppressElaboration = true; Policy.SuppressTagKeyword = !QT->isEnumeralType(); Policy.FullyQualifiedName = true; + Policy.UsePreferredNames = false; QT.getAsStringInternal(type_name, Policy); } @@ -1934,6 +1935,7 @@ static void GetDeclName(const clang::Decl* D, ASTContext& Context, PrintingPolicy Policy(Context.getPrintingPolicy()); Policy.SuppressTagKeyword = true; Policy.SuppressUnwrittenScope = true; + Policy.PrintCanonicalTypes = true; if (const TypeDecl* TD = dyn_cast(D)) { // This is a class, struct, or union member. QualType QT; diff --git a/unittests/CppInterOp/FunctionReflectionTest.cpp b/unittests/CppInterOp/FunctionReflectionTest.cpp index 3cb249e66..02a64f8ea 100644 --- a/unittests/CppInterOp/FunctionReflectionTest.cpp +++ b/unittests/CppInterOp/FunctionReflectionTest.cpp @@ -2112,6 +2112,48 @@ TEST(FunctionReflectionTest, GetFunctionCallWrapper) { auto op_callable = Cpp::MakeFunctionCallable(op); EXPECT_EQ(op_callable.getKind(), Cpp::JitCall::kGenericCall); + + Cpp::Declare(R"( + enum class MyEnum { A, B, C }; + template + class TemplatedEnum {}; + + namespace MyNameSpace { + enum class MyEnum { A, B, C }; + template + class TemplatedEnum {}; + } + )"); + + Cpp::TCppScope_t TemplatedEnum = Cpp::GetScope("TemplatedEnum"); + EXPECT_TRUE(TemplatedEnum); + + auto TAI_enum = + Cpp::TemplateArgInfo(Cpp::GetTypeFromScope(Cpp::GetNamed("MyEnum")), "1"); + Cpp::TCppScope_t TemplatedEnum_instantiated = + Cpp::InstantiateTemplate(TemplatedEnum, &TAI_enum, 1); + EXPECT_TRUE(TemplatedEnum_instantiated); + + Cpp::TCppObject_t obj = Cpp::Construct(TemplatedEnum_instantiated); + EXPECT_TRUE(obj); + Cpp::Destruct(obj, TemplatedEnum_instantiated); + obj = nullptr; + + Cpp::TCppScope_t MyNameSpace_TemplatedEnum = + Cpp::GetScope("TemplatedEnum", Cpp::GetScope("MyNameSpace")); + EXPECT_TRUE(TemplatedEnum); + + TAI_enum = Cpp::TemplateArgInfo(Cpp::GetTypeFromScope(Cpp::GetNamed( + "MyEnum", Cpp::GetScope("MyNameSpace"))), + "1"); + Cpp::TCppScope_t MyNameSpace_TemplatedEnum_instantiated = + Cpp::InstantiateTemplate(MyNameSpace_TemplatedEnum, &TAI_enum, 1); + EXPECT_TRUE(TemplatedEnum_instantiated); + + obj = Cpp::Construct(MyNameSpace_TemplatedEnum_instantiated); + EXPECT_TRUE(obj); + Cpp::Destruct(obj, MyNameSpace_TemplatedEnum_instantiated); + obj = nullptr; } TEST(FunctionReflectionTest, IsConstMethod) {