swift icon indicating copy to clipboard operation
swift copied to clipboard

[cxx-interop] Support using Swift Extensions from C++

Open mrousavy opened this issue 1 year ago • 0 comments

Motivation

I am building Swift classes that are exposed to C++.

Many of those Swift classes have functions that can throw errors, and since error throwing is not yet supported in C++ <> Swift interop (see https://github.com/swiftlang/swift/issues/75290), I need to use some workaround.

I have this Swift class:

public class MySwiftClass {
  func doSomething() throws -> Int {
    throw SomeError.failure
  }
}

Now since I cannot call doSomething() from C++ (because it throws), I wanted to create an extension to wrap it in a Result:

public extension MySwiftClass {
  func doSomethingResult() -> Result<Int, SomeError>
}

..but unfortunately doSomethingResult() is also not available in C++, because it is an extension.

Proposed solution

It would be great if the generated C++ binding class would also pull in any extensions declared in Swift.

Alternatives considered

No response

Additional information

No response

mrousavy avatar Jul 17 '24 15:07 mrousavy