Skip to content

Commit 5267c6a

Browse files
committed
If a member is a witness to any @objc requirement, don't call it a near miss.
When @objc inference was extended to look at the conformances of superclasses, the code that diagnosed near misses was not similarly updated, so we could end up producing a near-miss diagnostic on a declaration that was already a witness to another protocol. Use the same witness-finding logic that we use for @objc inference so this doesn't happen again. Fixes the rest of rdar://problem/27348369
1 parent b0a5669 commit 5267c6a

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4848,18 +4848,6 @@ void TypeChecker::checkConformancesInContext(DeclContext *dc,
48484848
// If there were any unsatisfied requirements, check whether there
48494849
// are any near-matches we should diagnose.
48504850
if (!unsatisfiedReqs.empty() && !anyInvalid) {
4851-
// Collect the set of witnesses that came from this context.
4852-
llvm::SmallPtrSet<ValueDecl *, 16> knownWitnesses;
4853-
for (auto conformance : conformances) {
4854-
conformance->forEachValueWitness(
4855-
nullptr,
4856-
[&](ValueDecl *req, ConcreteDeclRef witness) {
4857-
// If there is a witness, record it if it's within this context.
4858-
if (witness.getDecl() && witness.getDecl()->getDeclContext() == dc)
4859-
knownWitnesses.insert(witness.getDecl());
4860-
});
4861-
}
4862-
48634851
// Find all of the members that aren't used to satisfy
48644852
// requirements, and check whether they are close to an
48654853
// unsatisfied or defaulted requirement.
@@ -4869,8 +4857,12 @@ void TypeChecker::checkConformancesInContext(DeclContext *dc,
48694857
auto value = dyn_cast<ValueDecl>(member);
48704858
if (!value) continue;
48714859
if (isa<TypeDecl>(value)) continue;
4872-
if (knownWitnesses.count(value) > 0) continue;
48734860
if (!value->getFullName()) continue;
4861+
4862+
// If this member is a witness to any @objc requirement, ignore it.
4863+
if (!findWitnessedObjCRequirements(value, /*anySingleRequirement=*/true)
4864+
.empty())
4865+
continue;
48744866

48754867
// Find the unsatisfied requirements with the nearest-matching
48764868
// names.

test/decl/protocol/conforms/near_miss_objc.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,18 @@ 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
123+
// requirements.
124+
@objc protocol P8 {
125+
@objc optional func foo(exactMatch: Int)
126+
}
127+
128+
@objc protocol P9 : P8 {
129+
@objc optional func foo(nearMatch: Int)
130+
}
131+
132+
class C8Super : P8 { }
133+
134+
class C9Sub : C8Super, P9 {
135+
func foo(exactMatch: Int) { }
136+
}

0 commit comments

Comments
 (0)