Skip to content

Commit d7dbc23

Browse files
committed
Sema: ConformanceChecker::Adoptee is always nominal
1 parent 7bc5ac1 commit d7dbc23

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
@@ -3153,6 +3153,8 @@ ResolveWitnessResult
31533153
ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
31543154
assert(!isa<AssociatedTypeDecl>(requirement) && "Use resolveTypeWitnessVia*");
31553155

3156+
auto *nominal = Adoptee->getAnyNominal();
3157+
31563158
// Resolve all associated types before trying to resolve this witness.
31573159
resolveTypeWitnesses();
31583160

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

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

3232-
AccessScope nominalAccessScope =
3233-
Adoptee->getAnyNominal()->getFormalAccessScope(DC);
3232+
auto nominalAccessScope = nominal->getFormalAccessScope(DC);
32343233
auto check = checkWitness(nominalAccessScope, requirement, best);
32353234

32363235
switch (check.Kind) {
@@ -3446,10 +3445,9 @@ ResolveWitnessResult ConformanceChecker::resolveWitnessViaDerivation(
34463445

34473446
// Find the declaration that derives the protocol conformance.
34483447
NominalTypeDecl *derivingTypeDecl = nullptr;
3449-
if (auto *nominal = Adoptee->getAnyNominal()) {
3450-
if (nominal->derivesProtocolConformance(Proto))
3451-
derivingTypeDecl = nominal;
3452-
}
3448+
auto *nominal = Adoptee->getAnyNominal();
3449+
if (nominal->derivesProtocolConformance(Proto))
3450+
derivingTypeDecl = nominal;
34533451

34543452
if (!derivingTypeDecl) {
34553453
return ResolveWitnessResult::Missing;
@@ -5621,14 +5619,13 @@ void ConformanceChecker::checkConformance(MissingWitnessDiagnosisKind Kind) {
56215619
// Note that we check the module name to smooth over the difference
56225620
// between an imported Objective-C module and its overlay.
56235621
if (Proto->isSpecificProtocol(KnownProtocolKind::ObjectiveCBridgeable)) {
5624-
if (auto nominal = Adoptee->getAnyNominal()) {
5625-
if (!TC.Context.isTypeBridgedInExternalModule(nominal)) {
5626-
if (nominal->getParentModule() != DC->getParentModule() &&
5627-
!isInOverlayModuleForImportedModule(DC, nominal)) {
5628-
auto nominalModule = nominal->getParentModule();
5629-
TC.diagnose(Loc, diag::nonlocal_bridged_to_objc, nominal->getName(),
5630-
Proto->getName(), nominalModule->getName());
5631-
}
5622+
auto nominal = Adoptee->getAnyNominal();
5623+
if (!TC.Context.isTypeBridgedInExternalModule(nominal)) {
5624+
if (nominal->getParentModule() != DC->getParentModule() &&
5625+
!isInOverlayModuleForImportedModule(DC, nominal)) {
5626+
auto nominalModule = nominal->getParentModule();
5627+
TC.diagnose(Loc, diag::nonlocal_bridged_to_objc, nominal->getName(),
5628+
Proto->getName(), nominalModule->getName());
56325629
}
56335630
}
56345631
}

0 commit comments

Comments
 (0)