[cxx-interop] Generic Swift `enum` with associated value fails to build in C++
Description
While an enum with associated values works and can be represented in C++ perfectly, the same enum with one generic parameter introduced to it will somehow be exposed to C++, but fails to build due to seemingly different errors.
Without generic parameter
public enum ValueOrError {
case value(Int)
case error(String)
}
public func compute() -> ValueOrError {
return .value(5)
}
This can be called from C++ just fine:
SwiftModule::ValueOrError value = SwiftModule::getValue();
swift::Int i = value.getValue();
With generic parameter
public enum ValueOrError<T> {
case value(T)
case error(String)
}
public func compute() -> ValueOrError<Int> {
return .value(5)
}
Xcode shows me that the type exists, but the same code fails to build:
SwiftModule::ValueOrError<swift::Int> value = SwiftModule::getValue();
swift::Int i = value.getValue();
...it fails to build with the error "Out-of-line definition of 'compute' does not match any declaration in ...":
Reproduction
Swift
public enum ValueOrError<T> {
case value(T)
case error(String)
}
public func compute() -> ValueOrError<Int> {
return .value(5)
}
C++
SwiftModule::ValueOrError<swift::Int> value = SwiftModule::getValue();
swift::Int i = value.getValue();
Expected behavior
I expect the generic enum to be exposed to C++ as a templated class.
Environment
swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4) Target: arm64-apple-macosx14.0
Additional information
No response
Thanks for reporting this issue! I believe https://github.com/swiftlang/swift/pull/75372 might have fixed this, at least I could no longer reproduce the problem with the minimal code snippet attached to the report. Could you give it a try with a recent checkout of the main branch to verify if the problem is resolved for you? Alternatively, if you do not want to build the toolchain yourself, you can download a trunk development snapshot from here: https://www.swift.org/download/
Wow, nice stuff! I'll try that when I'm back in the office - thanks ! :)
I am closing the issue for now because I did not see any activity. Feel free to reopen if you still experience the issue.
@Xazax-hun how do releases in Swift compiler work, will #75372 be released with the next Xcode update?
Hey @mrousavy, unfortunately, I cannot share any details about future xcode releases or their schedules. :( As far as the open source Swift compiler is concerned, I would expect this fix to be part of the release after 6.0.