weird behaviour of llvm::linker::LinkInModule()

Hello!
I created a new llvm module (A) - to create a ‘glue’ code.
I want to call some functions from another module (B);
I load module B withing the same LLVMContext, and create a function declaration in module A via:
auto functionInAnotherModule = ModuleB.getFunction(callableName);
auto functionType = functionInAnotherModule->getFunctionType();
auto localFunction = llvm::Function::Create(functionType, llvm::GlobalValue::LinkageTypes::ExternalWeakLinkage, callableName, &ModuleA);

Function seems to be copied, together with complex types its using:
; ModuleID = ‘JitModule’
source_filename = “JitModule”
%struct._EN12RecordStreamE = type { %class.RecordStream }
declare extern_weak void @_EN12RecordStream4InitEPTsN18_EN12RecordStreamEEPvv(%struct._EN12RecordStreamE*, i8*)

… But later I’m not able to link in ModuleB to ModuleA using linker.linkInModule(std::move(ModuleB));
llvm says: Assertion failed: !(Pair.first != Ty && Pair.second == Ty) && “mapping to a source type”,…

Could someone point me what conceptually I did wrong?