Skip to content

Commit 82f9d50

Browse files
Xazax-hunGabor Horvath
authored andcommitted
🍒 [6.0][cxx-interop] Do not export enums with indirect associated values
Explanation: Indirect enum cases can trigger infinite recursion. This PR stops attempting to export them to C++. Scope: C++ reverse interop. Risk: Low, we skip the problematic pattern. Testing: Regression test added. Issue: rdar://134852756 Reviewer: @egorzhdan Original PR: #76167
1 parent f8e35f0 commit 82f9d50

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/AST/SwiftNameTranslation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ swift::cxx_translation::getDeclRepresentation(const ValueDecl *VD) {
263263
for (const auto *elementDecl : enumCase->getElements()) {
264264
if (!elementDecl->hasAssociatedValues())
265265
continue;
266+
if (elementDecl->isIndirect())
267+
return {Unsupported, UnrepresentableIndirectEnum};
266268
// Do not expose any enums with > 1
267269
// enum parameter, or any enum parameter
268270
// whose type we do not yet support.

test/Interop/SwiftToCxx/enums/swift-enum-implementation.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public enum E2 {
3333
case baz
3434
}
3535

36+
public enum Expr {
37+
case Const(Int)
38+
indirect case Neg(Expr)
39+
}
40+
3641
public struct S {
3742
public var x: Int64
3843

0 commit comments

Comments
 (0)