|
24 | 24 | #include "swift/AST/LazyResolver.h"
|
25 | 25 | #include "swift/AST/Module.h"
|
26 | 26 | #include "swift/AST/TypeLoc.h"
|
| 27 | +#include "swift/Basic/Fallthrough.h" |
27 | 28 | #include "llvm/ADT/APFloat.h"
|
28 | 29 | #include "llvm/ADT/SmallPtrSet.h"
|
29 | 30 | #include "llvm/ADT/SmallString.h"
|
@@ -2112,25 +2113,23 @@ getForeignRepresentable(Type type, ForeignLanguage language,
|
2112 | 2113 | if (nominal->hasClangNode() || nominal->isObjC()) {
|
2113 | 2114 | switch (language) {
|
2114 | 2115 | case ForeignLanguage::C:
|
2115 |
| - // Imported structs and enums are trivially representable in C. |
2116 |
| - // FIXME: This is not entirely true; we need to check that |
2117 |
| - // all of the exposed parts are representable in C. |
2118 |
| - if (isa<StructDecl>(nominal) || isa<EnumDecl>(nominal)) { |
2119 |
| - if (wasOptional) |
2120 |
| - break; |
2121 |
| - return { ForeignRepresentableKind::Trivial, nullptr }; |
2122 |
| - } |
2123 |
| - |
2124 |
| - // Imported classes and protocols are not. |
| 2116 | + // Imported classes and protocols are not representable in C. |
2125 | 2117 | if (isa<ClassDecl>(nominal) || isa<ProtocolDecl>(nominal))
|
2126 | 2118 | return failure();
|
2127 |
| - |
2128 |
| - llvm_unreachable("Unhandled nominal type declaration"); |
| 2119 | + SWIFT_FALLTHROUGH; |
2129 | 2120 |
|
2130 | 2121 | case ForeignLanguage::ObjectiveC:
|
2131 |
| - if (isa<StructDecl>(nominal) || isa<EnumDecl>(nominal)) |
2132 |
| - if (wasOptional) |
| 2122 | + if (isa<StructDecl>(nominal) || isa<EnumDecl>(nominal)) { |
| 2123 | + // Optional structs are not representable in (Objective-)C if they |
| 2124 | + // originally came from C, whether or not they are bridged. If they |
| 2125 | + // are defined in Swift, they are only representable if they are |
| 2126 | + // bridged (checked below). |
| 2127 | + if (wasOptional) { |
| 2128 | + if (nominal->hasClangNode()) |
| 2129 | + return failure(); |
2133 | 2130 | break;
|
| 2131 | + } |
| 2132 | + } |
2134 | 2133 |
|
2135 | 2134 | return { ForeignRepresentableKind::Trivial, nullptr };
|
2136 | 2135 | }
|
|
0 commit comments