Skip to content

Commit 8397c08

Browse files
committed
Sema: Remove duplicate logic for throwing accessor witness matching
getTypeOfMemberReference() already opens the accessor's thrown error type for us.
1 parent 05d5769 commit 8397c08

File tree

1 file changed

+14
-37
lines changed

1 file changed

+14
-37
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,14 +1172,16 @@ swift::matchWitness(WitnessChecker::RequirementEnvironmentCache &reqEnvCache,
11721172

11731173
reqLocator =
11741174
cs->getConstraintLocator(req, ConstraintLocator::ProtocolRequirement);
1175-
reqType =
1175+
auto reqTypeInfo =
11761176
cs->getTypeOfMemberReference(selfTy, req, dc,
11771177
/*isDynamicResult=*/false,
11781178
FunctionRefInfo::doubleBaseNameApply(),
1179-
reqLocator, &reqReplacements)
1180-
.adjustedReferenceType;
1179+
reqLocator, &reqReplacements);
1180+
reqType = reqTypeInfo.adjustedReferenceType;
11811181
reqType = reqType->getRValueType();
11821182

1183+
Type reqThrownError = reqTypeInfo.thrownErrorTypeOnAccess;
1184+
11831185
// For any type parameters we replaced in the witness, map them
11841186
// to the corresponding archetypes in the witness's context.
11851187
for (const auto &replacement : reqReplacements) {
@@ -1205,50 +1207,25 @@ swift::matchWitness(WitnessChecker::RequirementEnvironmentCache &reqEnvCache,
12051207
witnessType = witness->getInterfaceType();
12061208
witnessLocator =
12071209
cs->getConstraintLocator(req, LocatorPathElt::Witness(witness));
1210+
DeclReferenceType openWitnessTypeInfo;
1211+
12081212
if (witness->getDeclContext()->isTypeContext()) {
1209-
openWitnessType =
1213+
openWitnessTypeInfo =
12101214
cs->getTypeOfMemberReference(selfTy, witness, dc,
12111215
/*isDynamicResult=*/false,
12121216
FunctionRefInfo::doubleBaseNameApply(),
1213-
witnessLocator, &witnessReplacements)
1214-
.adjustedReferenceType;
1217+
witnessLocator, &witnessReplacements);
12151218
} else {
1216-
openWitnessType =
1219+
openWitnessTypeInfo =
12171220
cs->getTypeOfReference(
12181221
witness, FunctionRefInfo::doubleBaseNameApply(), witnessLocator,
1219-
/*useDC=*/nullptr, /*preparedOverload=*/nullptr)
1220-
.adjustedReferenceType;
1222+
/*useDC=*/nullptr, /*preparedOverload=*/nullptr);
12211223
}
1222-
openWitnessType = openWitnessType->getRValueType();
12231224

1224-
Type reqThrownError;
1225-
Type witnessThrownError;
1226-
1227-
if (auto *witnessASD = dyn_cast<AbstractStorageDecl>(witness)) {
1228-
auto *reqASD = cast<AbstractStorageDecl>(req);
1229-
1230-
// Dig out the thrown error types from the getter so we can compare them
1231-
// later.
1232-
auto getThrownErrorType = [](AbstractStorageDecl *asd) -> Type {
1233-
if (auto getter = asd->getEffectfulGetAccessor()) {
1234-
if (Type thrownErrorType = getter->getThrownInterfaceType()) {
1235-
return thrownErrorType;
1236-
} else if (getter->hasThrows()) {
1237-
return asd->getASTContext().getErrorExistentialType();
1238-
}
1239-
}
1240-
1241-
return asd->getASTContext().getNeverType();
1242-
};
1243-
1244-
reqThrownError = getThrownErrorType(reqASD);
1245-
reqThrownError = cs->openType(reqThrownError, reqReplacements,
1246-
reqLocator, /*preparedOverload=*/nullptr);
1225+
openWitnessType = openWitnessTypeInfo.adjustedReferenceType;
1226+
openWitnessType = openWitnessType->getRValueType();
12471227

1248-
witnessThrownError = getThrownErrorType(witnessASD);
1249-
witnessThrownError = cs->openType(witnessThrownError, witnessReplacements,
1250-
witnessLocator, /*preparedOverload=*/nullptr);
1251-
}
1228+
Type witnessThrownError = openWitnessTypeInfo.thrownErrorTypeOnAccess;
12521229

12531230
return std::make_tuple(std::nullopt, reqType, openWitnessType,
12541231
reqThrownError, witnessThrownError);

0 commit comments

Comments
 (0)