Open jpsim opened 1 year ago
@zoecarver
@AnthonyLatsis can we remove the C++ enums
label? It's polluting the regular C++ interop
label when creating PRs and completing the labels.
@hyp So you reckon we should use a single label for C++ and Swift features that share the same name? Enums are pretty similar, but what about macros? Or Cxx-specific features like templates?
I noticed that this already works in Swift toolchain from Xcode 15.4, but doesn't in 15.2. Maybe also works in 15.3, but I don't have it to test.
namespace S {
enum B {
Z,
X,
};
}
public enum S {
public struct B : Equatable, RawRepresentable {
public init(_ rawValue: UInt32)
public init(rawValue: UInt32)
public var rawValue: UInt32
}
// these are missing in 15.2
public static var Z: S.B { get }
public static var X: S.B { get }
}
Motivation
Currently only C++ "class enums" can be imported into Swift. This is fine for enums that are entirely under the user's control, but in some cases those APIs come from external dependencies or can't be modified for some reason (e.g. API compatibility).
Ideally there would still be a way to import these into Swift without having to write a shim wrapper re-exposing them.
Currently if you have this C++ code:
As far as I know the only way to construct the
first
member of theParent::Child::MyEnum
enum from Swift is to use thekMyEnumFirst
constant.If the enum is changed to a "class enum" then this works fine:
Solution
Ideally it should be possible to construct the
first
member of theParent::Child::MyEnum
enum from Swift just like a class enum would be imported.Alternatives considered
But if that isn't possible for some reason, then ideally the clang importer would generate accessors to all the enum fields in some other way:
Additional context
Thread in Swift Open Source Slack: https://swift-open-source.slack.com/archives/C03FAHQK8F7/p1678459701676699 PRs changing plain enums to enum classes to work around this issue: https://github.com/envoyproxy/envoy/pull/26036 and https://github.com/envoyproxy/envoy/pull/26037