Skip to content

Commit 736343f

Browse files
committed
Sema: Skip override checking for members of constrained extensions
When a method in an extension of a class looks like an override of a method from the base class, we emit a diagnostic. However due to a bug we used to skip this diagnostic for certain members of constrained extensions. Indeed it feels like we should not be doing this check at all for members of constrained extensions, so lets explicitly skip it, fixing a source compatibility problem that was introduced when the unrelated bug was fixed. Fixes <rdar://problem/57029805>, <https://bugs.swift.org/browse/SR-11740>.
1 parent 317c031 commit 736343f

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ static bool areOverrideCompatibleSimple(ValueDecl *decl,
234234
return false;
235235
}
236236

237+
// Ignore declarations that are defined inside constrained extensions.
238+
if (auto *ext = dyn_cast<ExtensionDecl>(parentDecl->getDeclContext()))
239+
if (ext->isConstrainedExtension())
240+
return false;
241+
237242
// The declarations must be of the same kind.
238243
if (decl->getKind() != parentDecl->getKind())
239244
return false;
@@ -1169,6 +1174,11 @@ bool swift::checkOverrides(ValueDecl *decl) {
11691174
// Otherwise, we have more checking to do.
11701175
}
11711176

1177+
// Members of constrained extensions are not considered to be overrides.
1178+
if (auto *ext = dyn_cast<ExtensionDecl>(decl->getDeclContext()))
1179+
if (ext->isConstrainedExtension())
1180+
return false;
1181+
11721182
// Accessor methods get overrides through their storage declaration, and
11731183
// all checking can be performed via that mechanism.
11741184
if (isa<AccessorDecl>(decl)) {

test/attr/attr_override.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,3 +626,25 @@ class SR_10198_Derived_1: SR_10198_Base_1 {
626626
init(_ arg1: Int) { super.init(SR_10198_Base_S()) } // okay, doesn't crash
627627
}
628628

629+
// SR-11740
630+
631+
public class SR_11740_Base<F, A> {}
632+
633+
public class SR_11740_Derived<F, A>
634+
: SR_11740_Base<SR_11740_Base<F, A>, A>,
635+
SR_11740_Q {}
636+
637+
public protocol SR_11740_P {}
638+
639+
public protocol SR_11740_Q: SR_11740_P {
640+
associatedtype A
641+
}
642+
643+
public extension SR_11740_Base where F: SR_11740_Q {
644+
static func foo(_: F.A) {}
645+
}
646+
647+
extension SR_11740_Derived where F: SR_11740_P {
648+
public static func foo(_: A) {}
649+
}
650+

0 commit comments

Comments
 (0)