Skip to content

Commit 2160114

Browse files
committed
Sema: ConformanceChecker::Adoptee is always nominal
1 parent 21868c1 commit 2160114

File tree

1 file changed

+28
-31
lines changed

1 file changed

+28
-31
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3155,6 +3155,8 @@ ResolveWitnessResult
31553155
ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
31563156
assert(!isa<AssociatedTypeDecl>(requirement) && "Use resolveTypeWitnessVia*");
31573157

3158+
auto *nominal = Adoptee->getAnyNominal();
3159+
31583160
// Resolve all associated types before trying to resolve this witness.
31593161
resolveTypeWitnesses();
31603162

@@ -3168,23 +3170,21 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
31683170

31693171
// Determine whether we can derive a witness for this requirement.
31703172
bool canDerive = false;
3171-
if (auto *nominal = Adoptee->getAnyNominal()) {
3172-
// Can a witness for this requirement be derived for this nominal type?
3173-
if (auto derivable = DerivedConformance::getDerivableRequirement(
3174-
nominal,
3175-
requirement)) {
3176-
if (derivable == requirement) {
3177-
// If it's the same requirement, we can derive it here.
3178-
canDerive = true;
3179-
} else {
3180-
// Otherwise, go satisfy the derivable requirement, which can introduce
3181-
// a member that could in turn satisfy *this* requirement.
3182-
auto derivableProto = cast<ProtocolDecl>(derivable->getDeclContext());
3183-
if (auto conformance =
3184-
TC.conformsToProtocol(Adoptee, derivableProto, DC, None)) {
3185-
if (conformance->isConcrete())
3186-
(void)conformance->getConcrete()->getWitnessDecl(derivable, &TC);
3187-
}
3173+
// Can a witness for this requirement be derived for this nominal type?
3174+
if (auto derivable = DerivedConformance::getDerivableRequirement(
3175+
nominal,
3176+
requirement)) {
3177+
if (derivable == requirement) {
3178+
// If it's the same requirement, we can derive it here.
3179+
canDerive = true;
3180+
} else {
3181+
// Otherwise, go satisfy the derivable requirement, which can introduce
3182+
// a member that could in turn satisfy *this* requirement.
3183+
auto derivableProto = cast<ProtocolDecl>(derivable->getDeclContext());
3184+
if (auto conformance =
3185+
TC.conformsToProtocol(Adoptee, derivableProto, DC, None)) {
3186+
if (conformance->isConcrete())
3187+
(void)conformance->getConcrete()->getWitnessDecl(derivable, &TC);
31883188
}
31893189
}
31903190
}
@@ -3231,8 +3231,7 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
32313231
});
32323232
}
32333233

3234-
AccessScope nominalAccessScope =
3235-
Adoptee->getAnyNominal()->getFormalAccessScope(DC);
3234+
auto nominalAccessScope = nominal->getFormalAccessScope(DC);
32363235
auto check = checkWitness(nominalAccessScope, requirement, best);
32373236

32383237
switch (check.Kind) {
@@ -3448,10 +3447,9 @@ ResolveWitnessResult ConformanceChecker::resolveWitnessViaDerivation(
34483447

34493448
// Find the declaration that derives the protocol conformance.
34503449
NominalTypeDecl *derivingTypeDecl = nullptr;
3451-
if (auto *nominal = Adoptee->getAnyNominal()) {
3452-
if (nominal->derivesProtocolConformance(Proto))
3453-
derivingTypeDecl = nominal;
3454-
}
3450+
auto *nominal = Adoptee->getAnyNominal();
3451+
if (nominal->derivesProtocolConformance(Proto))
3452+
derivingTypeDecl = nominal;
34553453

34563454
if (!derivingTypeDecl) {
34573455
return ResolveWitnessResult::Missing;
@@ -5606,14 +5604,13 @@ void ConformanceChecker::checkConformance(MissingWitnessDiagnosisKind Kind) {
56065604
// Note that we check the module name to smooth over the difference
56075605
// between an imported Objective-C module and its overlay.
56085606
if (Proto->isSpecificProtocol(KnownProtocolKind::ObjectiveCBridgeable)) {
5609-
if (auto nominal = Adoptee->getAnyNominal()) {
5610-
if (!TC.Context.isTypeBridgedInExternalModule(nominal)) {
5611-
if (nominal->getParentModule() != DC->getParentModule() &&
5612-
!isInOverlayModuleForImportedModule(DC, nominal)) {
5613-
auto nominalModule = nominal->getParentModule();
5614-
TC.diagnose(Loc, diag::nonlocal_bridged_to_objc, nominal->getName(),
5615-
Proto->getName(), nominalModule->getName());
5616-
}
5607+
auto nominal = Adoptee->getAnyNominal();
5608+
if (!TC.Context.isTypeBridgedInExternalModule(nominal)) {
5609+
if (nominal->getParentModule() != DC->getParentModule() &&
5610+
!isInOverlayModuleForImportedModule(DC, nominal)) {
5611+
auto nominalModule = nominal->getParentModule();
5612+
TC.diagnose(Loc, diag::nonlocal_bridged_to_objc, nominal->getName(),
5613+
Proto->getName(), nominalModule->getName());
56175614
}
56185615
}
56195616
}

0 commit comments

Comments
 (0)