Fix synthesis of 'override' and 'required' on initializers (#20548)

This is actually two separate problems:
- 'override' wasn't getting added to initializers in deserialization
- 'override' was getting added when inheriting a 'required' initializer,
  even though it's normally an error to write that

Needed for parseable interfaces.
This commit is contained in:
Jordan Rose
2018-11-13 16:54:53 -08:00
committed by GitHub
parent a21a71d7da
commit 40cfc458e2
4 changed files with 54 additions and 9 deletions

View File

@@ -2222,6 +2222,15 @@ ModuleFile::getDeclChecked(DeclID DID) {
return deserialized;
}
template <typename DERIVED>
static bool attributeChainContains(DeclAttribute *attr) {
DeclAttributes tempAttrs;
tempAttrs.setRawAttributeChain(attr);
static_assert(std::is_trivially_destructible<DeclAttributes>::value,
"must not try to destroy the attribute chain");
return tempAttrs.hasAttribute<DERIVED>();
}
Expected<Decl *>
ModuleFile::getDeclCheckedImpl(DeclID DID) {
if (DID == 0)
@@ -2892,9 +2901,16 @@ ModuleFile::getDeclCheckedImpl(DeclID DID) {
ctor->setStubImplementation(true);
if (initKind.hasValue())
ctor->setInitKind(initKind.getValue());
ctor->setOverriddenDecl(cast_or_null<ConstructorDecl>(overridden.get()));
ctor->setNeedsNewVTableEntry(needsNewVTableEntry);
ctor->setOverriddenDecl(cast_or_null<ConstructorDecl>(overridden.get()));
if (auto *overridden = ctor->getOverriddenDecl()) {
if (!attributeChainContains<RequiredAttr>(DAttrs) ||
!overridden->isRequired()) {
AddAttribute(new (ctx) OverrideAttr(SourceLoc()));
}
}
if (auto defaultArgumentResilienceExpansion = getActualResilienceExpansion(
rawDefaultArgumentResilienceExpansion)) {
ctor->setDefaultArgumentResilienceExpansion(