Skip to content

Commit 1b91f00

Browse files
authored
Merge pull request #17733 from DougGregor/refactor-override-checking
2 parents 7f72944 + 19aa552 commit 1b91f00

File tree

7 files changed

+390
-356
lines changed

7 files changed

+390
-356
lines changed

include/swift/AST/Attr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,7 @@ class DeclAttributes {
13851385
/// Retrieve the first attribute of the given attribute class.
13861386
template <typename ATTR>
13871387
const ATTR *getAttribute(bool AllowInvalid = false) const {
1388-
return const_cast<DeclAttributes *>(this)->getAttribute<ATTR>();
1388+
return const_cast<DeclAttributes *>(this)->getAttribute<ATTR>(AllowInvalid);
13891389
}
13901390

13911391
template <typename ATTR>

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,15 +1976,6 @@ NOTE(overridden_here,none,
19761976
NOTE(overridden_here_can_be_objc,none,
19771977
"add '@objc' to make this declaration overridable", ())
19781978

1979-
ERROR(override_objc_type_mismatch_method,none,
1980-
"overriding method with selector %0 has incompatible type %1",
1981-
(ObjCSelector, Type))
1982-
ERROR(override_objc_type_mismatch_subscript,none,
1983-
"overriding %select{|indexed |keyed }0subscript with incompatible type "
1984-
"%1",
1985-
(unsigned, Type))
1986-
NOTE(overridden_here_with_type,none,
1987-
"overridden declaration here has type %0", (Type))
19881979
ERROR(missing_override,none,
19891980
"overriding declaration requires an 'override' keyword", ())
19901981

lib/AST/NameLookup.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,8 @@ bool swift::removeOverriddenDecls(SmallVectorImpl<ValueDecl*> &decls) {
8484
if (decls.size() < 2)
8585
return false;
8686

87-
auto lazyResolver = decls.front()->getASTContext().getLazyResolver();
8887
llvm::SmallPtrSet<ValueDecl*, 8> overridden;
8988
for (auto decl : decls) {
90-
// Compute enough information to make the overridden-declaration available.
91-
if (lazyResolver)
92-
lazyResolver->resolveOverriddenDecl(decl);
93-
9489
while (auto overrides = decl->getOverriddenDecl()) {
9590
overridden.insert(overrides);
9691

@@ -105,10 +100,6 @@ bool swift::removeOverriddenDecls(SmallVectorImpl<ValueDecl*> &decls) {
105100
/// cause instead (incomplete circularity detection).
106101
assert(decl != overrides && "Circular class inheritance?");
107102
decl = overrides;
108-
109-
if (lazyResolver)
110-
lazyResolver->resolveOverriddenDecl(decl);
111-
112103
continue;
113104
}
114105

@@ -1913,9 +1904,6 @@ bool DeclContext::lookupQualified(Type type,
19131904
// If the declaration has an override, name lookup will also have
19141905
// found the overridden method. Skip this declaration, because we
19151906
// prefer the overridden method.
1916-
if (typeResolver)
1917-
typeResolver->resolveOverriddenDecl(decl);
1918-
19191907
if (decl->getOverriddenDecl())
19201908
continue;
19211909

lib/ClangImporter/ImportDecl.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6389,6 +6389,12 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(
63896389
}
63906390

63916391
void SwiftDeclConverter::recordObjCOverride(AbstractFunctionDecl *decl) {
6392+
// Make sure that we always set the overriden declarations.
6393+
SWIFT_DEFER {
6394+
if (!decl->overriddenDeclsComputed())
6395+
(void)decl->setOverriddenDecls({ });
6396+
};
6397+
63926398
// Figure out the class in which this method occurs.
63936399
if (!decl->getDeclContext()->isTypeContext())
63946400
return;
@@ -6418,6 +6424,7 @@ void SwiftDeclConverter::recordObjCOverride(AbstractFunctionDecl *decl) {
64186424
func->getObjCSelector() != foundFunc->getObjCSelector())
64196425
continue;
64206426
func->setOverriddenDecl(foundFunc);
6427+
func->getAttrs().add(new (func->getASTContext()) OverrideAttr(true));
64216428
return;
64226429
}
64236430
// Set constructor override.
@@ -6428,6 +6435,8 @@ void SwiftDeclConverter::recordObjCOverride(AbstractFunctionDecl *decl) {
64286435
ctor->getObjCSelector() != memberCtor->getObjCSelector())
64296436
continue;
64306437
ctor->setOverriddenDecl(memberCtor);
6438+
ctor->getAttrs().add(new (ctor->getASTContext()) OverrideAttr(true));
6439+
64316440
// Propagate 'required' to subclass initializers.
64326441
if (memberCtor->isRequired() &&
64336442
!ctor->getAttrs().hasAttribute<RequiredAttr>()) {

0 commit comments

Comments
 (0)