Skip to content

Commit 2f89495

Browse files
authored
Merge pull request #5347 from DougGregor/objc-near-miss-suppress
Suppress silly diagnostics from `@objc` near-miss checking
2 parents 569687e + da2a7ce commit 2f89495

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 9 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,9 +4857,17 @@ 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;
48744861

4862+
// If this declaration overrides another declaration, the signature is
4863+
// fixed; don't complain about near misses.
4864+
if (value->getOverriddenDecl()) continue;
4865+
4866+
// If this member is a witness to any @objc requirement, ignore it.
4867+
if (!findWitnessedObjCRequirements(value, /*anySingleRequirement=*/true)
4868+
.empty())
4869+
continue;
4870+
48754871
// Find the unsatisfied requirements with the nearest-matching
48764872
// names.
48774873
SmallVector<ValueDecl *, 4> bestOptionalReqs;

test/decl/protocol/conforms/near_miss_objc.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,28 @@ 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+
}
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)