@@ -3153,6 +3153,8 @@ ResolveWitnessResult
3153
3153
ConformanceChecker::resolveWitnessViaLookup (ValueDecl *requirement) {
3154
3154
assert (!isa<AssociatedTypeDecl>(requirement) && " Use resolveTypeWitnessVia*" );
3155
3155
3156
+ auto *nominal = Adoptee->getAnyNominal ();
3157
+
3156
3158
// Resolve all associated types before trying to resolve this witness.
3157
3159
resolveTypeWitnesses ();
3158
3160
@@ -3166,23 +3168,21 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
3166
3168
3167
3169
// Determine whether we can derive a witness for this requirement.
3168
3170
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);
3186
3186
}
3187
3187
}
3188
3188
}
@@ -3229,8 +3229,7 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
3229
3229
});
3230
3230
}
3231
3231
3232
- AccessScope nominalAccessScope =
3233
- Adoptee->getAnyNominal ()->getFormalAccessScope (DC);
3232
+ auto nominalAccessScope = nominal->getFormalAccessScope (DC);
3234
3233
auto check = checkWitness (nominalAccessScope, requirement, best);
3235
3234
3236
3235
switch (check.Kind ) {
@@ -3446,10 +3445,9 @@ ResolveWitnessResult ConformanceChecker::resolveWitnessViaDerivation(
3446
3445
3447
3446
// Find the declaration that derives the protocol conformance.
3448
3447
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;
3453
3451
3454
3452
if (!derivingTypeDecl) {
3455
3453
return ResolveWitnessResult::Missing;
@@ -5621,14 +5619,13 @@ void ConformanceChecker::checkConformance(MissingWitnessDiagnosisKind Kind) {
5621
5619
// Note that we check the module name to smooth over the difference
5622
5620
// between an imported Objective-C module and its overlay.
5623
5621
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 ());
5632
5629
}
5633
5630
}
5634
5631
}
0 commit comments