I experience an issue when building a Swift framework and generating the C++ header.
Following Swift code reduced to the simplest to reproduce.
import Foundation
public class MyObject {
public init() { }
}
public class MyModule {
public init() { }
public func getArray() -> [MyObject] {
let objects: [MyObject] = []
return objects
}
}
The error "use of undeclared identifier 'MyObject' " occur in the generated header at the line
SWIFT_INLINE_THUNK swift::Array getArray()
header extract:
class SWIFT_SYMBOL("s:9SwiftSide8MyModuleC") MyModule : public swift::_impl::RefCountedClass {
public:
using RefCountedClass::RefCountedClass;
using RefCountedClass::operator=;
static SWIFT_INLINE_THUNK MyModule init() SWIFT_SYMBOL("s:9SwiftSide8MyModuleCACycfc");
SWIFT_INLINE_THUNK swift::Array<MyObject> getArray() SWIFT_SYMBOL("s:9SwiftSide8MyModuleC8getArraySayAA0C6ObjectCGyF");
protected:
SWIFT_INLINE_THUNK MyModule(void * _Nonnull ptr) noexcept : RefCountedClass(ptr) {}
private:
friend class _impl::_impl_MyModule;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wc++17-extensions"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wreserved-identifier"
typedef char $s9SwiftSide8MyModuleCD;
static inline constexpr $s9SwiftSide8MyModuleCD __swift_mangled_name = 0;
#pragma clang diagnostic pop
#pragma clang diagnostic pop
};
Note the that if MyObject is a struct instead of a class, there is no errors.
Xcode 15.2, Swift 5.9.2
Any idea ?