Skip to content

Commit 147ba3d

Browse files
authored
Merge pull request #65365 from hyp/eng/protocol-enum-type-fix
[interop][SwiftToCxx] do not expose enums with a protocol type associ…
2 parents 20e1b38 + 20704ec commit 147ba3d

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/AST/SwiftNameTranslation.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,11 @@ swift::cxx_translation::getDeclRepresentation(const ValueDecl *VD) {
249249
return {Unsupported, UnrepresentableEnumCaseTuple};
250250
for (const auto *param : *params) {
251251
auto paramType = param->getInterfaceType();
252-
if (!paramType->is<GenericTypeParamType>() &&
253-
!paramType->getNominalOrBoundGenericNominal())
254-
return {Unsupported, UnrepresentableEnumCaseType};
252+
if (!paramType->is<GenericTypeParamType>()) {
253+
auto *nominal = paramType->getNominalOrBoundGenericNominal();
254+
if (!nominal || isa<ProtocolDecl>(nominal))
255+
return {Unsupported, UnrepresentableEnumCaseType};
256+
}
255257
}
256258
}
257259
}

test/Interop/SwiftToCxx/unsupported/unsupported-enums-in-cxx.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ public indirect enum unsupportedEnumIndirect {
2727
case B
2828
}
2929

30+
@_expose(Cxx) // expected-error {{enum 'unsupportedEnumProtocolType' can not be represented in C++ as one of its cases has an associated value with type that can't be represented in C++}}
31+
public enum unsupportedEnumProtocolType {
32+
case A
33+
case B(Error)
34+
}

0 commit comments

Comments
 (0)