|
26 | 26 |
|
27 | 27 | using namespace swift;
|
28 | 28 |
|
| 29 | +/// Check whether given declaration comes from the .swiftinterface file. |
| 30 | +static bool inSwiftInterfaceContext(NominalTypeDecl *typeDecl) { |
| 31 | + auto *SF = typeDecl->getDeclContext()->getParentSourceFile(); |
| 32 | + return SF && SF->Kind == SourceFileKind::Interface; |
| 33 | +} |
| 34 | + |
| 35 | +static ValueDecl *findMember(NominalTypeDecl *typeDecl, Identifier memberName) { |
| 36 | + auto members = typeDecl->lookupDirect(memberName); |
| 37 | + return members.size() == 1 ? members.front() : nullptr; |
| 38 | +} |
| 39 | + |
29 | 40 | static PatternBindingDecl *injectVariable(DeclContext *DC, Identifier name,
|
30 | 41 | Type type,
|
31 | 42 | VarDecl::Introducer introducer,
|
@@ -284,6 +295,15 @@ TypeDecl *GetTypeWrapperStorage::evaluate(Evaluator &evaluator,
|
284 | 295 |
|
285 | 296 | auto &ctx = parent->getASTContext();
|
286 | 297 |
|
| 298 | + // .swiftinterfaces have both attribute and a synthesized member |
| 299 | + // (if it's public), so in this case we need use existing declaration |
| 300 | + // if available. |
| 301 | + if (inSwiftInterfaceContext(parent)) { |
| 302 | + if (auto *storage = dyn_cast_or_null<TypeDecl>( |
| 303 | + findMember(parent, ctx.Id_TypeWrapperStorage))) |
| 304 | + return storage; |
| 305 | + } |
| 306 | + |
287 | 307 | TypeDecl *storage = nullptr;
|
288 | 308 | if (isa<ProtocolDecl>(parent)) {
|
289 | 309 | // If type wrapper is associated with a protocol, we need to
|
@@ -320,6 +340,15 @@ GetTypeWrapperProperty::evaluate(Evaluator &evaluator,
|
320 | 340 | if (!typeWrapper)
|
321 | 341 | return nullptr;
|
322 | 342 |
|
| 343 | + // .swiftinterfaces have both attribute and a synthesized member |
| 344 | + // (if it's public), so in this case we need use existing declaration |
| 345 | + // if available. |
| 346 | + if (inSwiftInterfaceContext(parent)) { |
| 347 | + if (auto *storage = dyn_cast_or_null<VarDecl>( |
| 348 | + findMember(parent, ctx.Id_TypeWrapperProperty))) |
| 349 | + return storage; |
| 350 | + } |
| 351 | + |
323 | 352 | auto *storage = parent->getTypeWrapperStorageDecl();
|
324 | 353 | assert(storage);
|
325 | 354 |
|
|
0 commit comments