Skip to content

Commit da2a7ce

Browse files
committed
Don't complain about near misses for declarations that are overrides.
An overriding declaration doesn't have a choice about its signature, because the signature is dictated by the overridden declaration. Therefore, don't produce a warning for it. Fixes rdar://problem/28524237.
1 parent 5267c6a commit da2a7ce

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4858,7 +4858,11 @@ void TypeChecker::checkConformancesInContext(DeclContext *dc,
48584858
if (!value) continue;
48594859
if (isa<TypeDecl>(value)) continue;
48604860
if (!value->getFullName()) continue;
4861-
4861+
4862+
// If this declaration overrides another declaration, the signature is
4863+
// fixed; don't complain about near misses.
4864+
if (value->getOverriddenDecl()) continue;
4865+
48624866
// If this member is a witness to any @objc requirement, ignore it.
48634867
if (!findWitnessedObjCRequirements(value, /*anySingleRequirement=*/true)
48644868
.empty())

test/decl/protocol/conforms/near_miss_objc.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class C7a : P7 {
119119
// expected-note@-4{{make 'method(foo:)' private to silence this warning}}
120120
}
121121

122-
// Don't complain about near-misses that satisfy other protocol
122+
// Don't complain about near misses that satisfy other protocol
123123
// requirements.
124124
@objc protocol P8 {
125125
@objc optional func foo(exactMatch: Int)
@@ -134,3 +134,13 @@ class C8Super : P8 { }
134134
class C9Sub : C8Super, P9 {
135135
func foo(exactMatch: Int) { }
136136
}
137+
138+
// Don't complain about overriding methods that are near misses;
139+
// the user cannot make it satisfy the protocol requirement.
140+
class C10Super {
141+
func foo(nearMatch: Int) { }
142+
}
143+
144+
class C10Sub : C10Super, P8 {
145+
override func foo(nearMatch: Int) { }
146+
}

0 commit comments

Comments
 (0)