Skip to content

Commit 97c25ae

Browse files
committed
[interop][SwiftToCxx] nested types are not yet supported so do not emit references to them
1 parent f623683 commit 97c25ae

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,6 +1849,8 @@ ERROR(expose_protocol_to_cxx_unsupported,none,
18491849
"protocol %0 can not yet be represented in C++", (ValueDecl *))
18501850
ERROR(expose_move_only_to_cxx,none,
18511851
"noncopyable %kind0 can not yet be represented in C++", (ValueDecl *))
1852+
ERROR(expose_nested_type_to_cxx,none,
1853+
"nested %kind0 can not yet be represented in C++", (ValueDecl *))
18521854
ERROR(unexposed_other_decl_in_cxx,none,
18531855
"%kind0 is not yet exposed to C++", (ValueDecl *))
18541856
ERROR(unsupported_other_decl_in_cxx,none,

include/swift/AST/SwiftNameTranslation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ enum RepresentationError {
7979
UnrepresentableEnumCaseTuple,
8080
UnrepresentableProtocol,
8181
UnrepresentableMoveOnly,
82+
UnrepresentableNested,
8283
};
8384

8485
/// Constructs a diagnostic that describes the given C++ representation error.

lib/AST/SwiftNameTranslation.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ swift::cxx_translation::getDeclRepresentation(const ValueDecl *VD) {
235235
genericSignature =
236236
typeDecl->getGenericSignature().getCanonicalSignature();
237237
}
238+
// Nested types are not yet supported.
239+
if (!typeDecl->hasClangNode() &&
240+
isa_and_nonnull<NominalTypeDecl>(
241+
typeDecl->getDeclContext()->getAsDecl()))
242+
return {Unsupported, UnrepresentableNested};
238243
}
239244
if (const auto *varDecl = dyn_cast<VarDecl>(VD)) {
240245
// Check if any property accessor throws, do not expose it in that case.
@@ -321,5 +326,7 @@ swift::cxx_translation::diagnoseRepresenationError(RepresentationError error,
321326
return Diagnostic(diag::expose_protocol_to_cxx_unsupported, vd);
322327
case UnrepresentableMoveOnly:
323328
return Diagnostic(diag::expose_move_only_to_cxx, vd);
329+
case UnrepresentableNested:
330+
return Diagnostic(diag::expose_nested_type_to_cxx, vd);
324331
}
325332
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,7 @@ public distributed actor DistributedActorClass {
6464

6565
@_expose(Cxx) // ok
6666
nonisolated public var prop2: Int { 42 }
67+
68+
@_expose(Cxx) // expected-error {{nested struct 'NestedStruct' can not yet be represented in C++}}
69+
public struct NestedStruct {}
6770
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,11 @@ public protocol TestProtocol {}
3434
public typealias unsupportedTypeAlias = () -> (Float, Float)
3535

3636
// CHECK: // Unavailable in C++: Swift type alias 'unsupportedTypeAlias'
37+
38+
public struct Container {
39+
public struct NestedStruct {}
40+
}
41+
42+
public typealias unsupportedTypeAliasNested = Container.NestedStruct
43+
44+
// CHECK: // Unavailable in C++: Swift type alias 'unsupportedTypeAliasNested'

0 commit comments

Comments
 (0)