diff --git a/lib/CppInterOp/CppInterOp.cpp b/lib/CppInterOp/CppInterOp.cpp index 73d61d0d6..319d3d3df 100755 --- a/lib/CppInterOp/CppInterOp.cpp +++ b/lib/CppInterOp/CppInterOp.cpp @@ -1966,9 +1966,24 @@ void collect_type_info(const FunctionDecl* FD, QualType& QT, PrintingPolicy Policy(C.getPrintingPolicy()); Policy.SuppressElaboration = true; refType = kNotReference; - if (QT->isRecordType() && forArgument) { - get_type_as_string(QT, type_name, C, Policy); - return; + if (QT->isRecordType()) { + if (forArgument) { + get_type_as_string(QT, type_name, C, Policy); + return; + } + if (auto* CXXRD = QT->getAsCXXRecordDecl()) { + if (CXXRD->isLambda()) { + std::string fn_name; + llvm::raw_string_ostream stream(fn_name); + Policy.FullyQualifiedName = true; + Policy.SuppressUnwrittenScope = true; + FD->getNameForDiagnostic(stream, Policy, + /*Qualified=*/false); + type_name = "__internal_CppInterOp::function::result_type"; + return; + } + } } if (QT->isFunctionPointerType()) { std::string fp_typedef_name; @@ -3223,6 +3238,17 @@ TInterp_t CreateInterpreter(const std::vector& Args /*={}*/, llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get()); } + I->declare(R"( + namespace __internal_CppInterOp { + template + struct function; + template + struct function { + typedef Res result_type; + }; + } // namespace __internal_CppInterOp + )"); + sInterpreters->emplace_back(I, /*Owned=*/true); return I; diff --git a/unittests/CppInterOp/FunctionReflectionTest.cpp b/unittests/CppInterOp/FunctionReflectionTest.cpp index 02a64f8ea..4581295fe 100644 --- a/unittests/CppInterOp/FunctionReflectionTest.cpp +++ b/unittests/CppInterOp/FunctionReflectionTest.cpp @@ -2154,6 +2154,19 @@ TEST(FunctionReflectionTest, GetFunctionCallWrapper) { EXPECT_TRUE(obj); Cpp::Destruct(obj, MyNameSpace_TemplatedEnum_instantiated); obj = nullptr; + + Cpp::Declare(R"( + auto get_fn(int x) { return [x](int y){ return x + y; }; } + )"); + + Cpp::TCppScope_t get_fn = Cpp::GetNamed("get_fn"); + EXPECT_TRUE(get_fn); + + auto get_fn_callable = Cpp::MakeFunctionCallable(get_fn); + EXPECT_EQ(get_fn_callable.getKind(), Cpp::JitCall::kGenericCall); + + EXPECT_TRUE(Cpp::IsLambdaClass(Cpp::GetFunctionReturnType(get_fn))); + EXPECT_FALSE(Cpp::IsLambdaClass(Cpp::GetFunctionReturnType(bar))); } TEST(FunctionReflectionTest, IsConstMethod) {