@@ -3155,6 +3155,8 @@ ResolveWitnessResult
3155
3155
ConformanceChecker::resolveWitnessViaLookup (ValueDecl *requirement) {
3156
3156
assert (!isa<AssociatedTypeDecl>(requirement) && " Use resolveTypeWitnessVia*" );
3157
3157
3158
+ auto *nominal = Adoptee->getAnyNominal ();
3159
+
3158
3160
// Resolve all associated types before trying to resolve this witness.
3159
3161
resolveTypeWitnesses ();
3160
3162
@@ -3168,23 +3170,21 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
3168
3170
3169
3171
// Determine whether we can derive a witness for this requirement.
3170
3172
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);
3188
3188
}
3189
3189
}
3190
3190
}
@@ -3231,8 +3231,7 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
3231
3231
});
3232
3232
}
3233
3233
3234
- AccessScope nominalAccessScope =
3235
- Adoptee->getAnyNominal ()->getFormalAccessScope (DC);
3234
+ auto nominalAccessScope = nominal->getFormalAccessScope (DC);
3236
3235
auto check = checkWitness (nominalAccessScope, requirement, best);
3237
3236
3238
3237
switch (check.Kind ) {
@@ -3448,10 +3447,9 @@ ResolveWitnessResult ConformanceChecker::resolveWitnessViaDerivation(
3448
3447
3449
3448
// Find the declaration that derives the protocol conformance.
3450
3449
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;
3455
3453
3456
3454
if (!derivingTypeDecl) {
3457
3455
return ResolveWitnessResult::Missing;
@@ -5606,14 +5604,13 @@ void ConformanceChecker::checkConformance(MissingWitnessDiagnosisKind Kind) {
5606
5604
// Note that we check the module name to smooth over the difference
5607
5605
// between an imported Objective-C module and its overlay.
5608
5606
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 ());
5617
5614
}
5618
5615
}
5619
5616
}
0 commit comments