Skip to content

Commit 27ac660

Browse files
authored
Merge pull request #4648 from DougGregor/infer-objc-superclasses
2 parents 0272536 + 7e3c13c commit 27ac660

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ matchWitness(TypeChecker &tc,
900900
static RequirementMatch
901901
matchWitness(TypeChecker &tc,
902902
ProtocolDecl *proto,
903-
NormalProtocolConformance *conformance,
903+
ProtocolConformance *conformance,
904904
DeclContext *dc, ValueDecl *req, ValueDecl *witness) {
905905
using namespace constraints;
906906

@@ -4945,6 +4945,26 @@ TypeChecker::findWitnessedObjCRequirements(const ValueDecl *witness,
49454945
if ((*conformance)->getWitness(req, this).getDecl() == witness) {
49464946
result.push_back(req);
49474947
if (anySingleRequirement) return result;
4948+
continue;
4949+
}
4950+
4951+
// If we have an inherited conformance, check whether the potential
4952+
// witness matches the requirement.
4953+
// FIXME: for now, don't even try this with generics involved. We
4954+
// should be tracking how subclasses implement optional requirements,
4955+
// in which case the getWitness() check above would suffice.
4956+
if (req->getAttrs().hasAttribute<OptionalAttr>() &&
4957+
isa<InheritedProtocolConformance>(*conformance)) {
4958+
auto normal = (*conformance)->getRootNormalConformance();
4959+
if (!(*conformance)->getDeclContext()->getGenericSignatureOfContext() &&
4960+
!normal->getDeclContext()->getGenericSignatureOfContext() &&
4961+
matchWitness(*this, proto, *conformance, witness->getDeclContext(),
4962+
req, const_cast<ValueDecl *>(witness)).Kind
4963+
== MatchKind::ExactMatch) {
4964+
result.push_back(req);
4965+
if (anySingleRequirement) return result;
4966+
continue;
4967+
}
49484968
}
49494969
}
49504970
}

test/attr/attr_objc.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,7 +2164,7 @@ class SuperclassImplementsProtocol : InferFromProtocol { }
21642164

21652165
// Note: no inference for subclasses
21662166
class SubclassInfersFromProtocol1 : SuperclassImplementsProtocol {
2167-
// CHECK: {{^}} func method1(value: Int)
2167+
// CHECK: {{^}} @objc func method1(value: Int)
21682168
func method1(value: Int) { }
21692169
}
21702170

@@ -2173,7 +2173,7 @@ class SubclassInfersFromProtocol2 : SuperclassImplementsProtocol {
21732173
}
21742174

21752175
extension SubclassInfersFromProtocol2 {
2176-
// CHECK: {{^}} func method1(value: Int)
2176+
// CHECK: {{^}} @objc dynamic func method1(value: Int)
21772177
func method1(value: Int) { }
21782178
}
21792179

0 commit comments

Comments
 (0)