Skip to content

Commit 6172fcc

Browse files
authored
Merge pull request #27975 from CodaFi/trompe-l-ambda
[Gardening] Switch an Out Parameter To a Tuple
2 parents 8a69f88 + ff97519 commit 6172fcc

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5374,22 +5374,18 @@ void TypeChecker::inferDefaultWitnesses(ProtocolDecl *proto) {
53745374
DefaultWitnessChecker checker(Context, proto);
53755375

53765376
// Find the default for the given associated type.
5377-
auto findAssociatedTypeDefault =
5378-
[&](AssociatedTypeDecl *assocType,
5379-
AssociatedTypeDecl **defaultedAssocTypeOut = nullptr) -> Type {
5377+
auto findAssociatedTypeDefault = [](AssociatedTypeDecl *assocType)
5378+
-> std::pair<Type, AssociatedTypeDecl *> {
53805379
auto defaultedAssocType =
53815380
AssociatedTypeInference::findDefaultedAssociatedType(assocType);
53825381
if (!defaultedAssocType)
5383-
return nullptr;
5382+
return {Type(), nullptr};
53845383

53855384
Type defaultType = defaultedAssocType->getDefaultDefinitionType();
53865385
if (!defaultType)
5387-
return nullptr;
5388-
5389-
if (defaultedAssocTypeOut)
5390-
*defaultedAssocTypeOut = defaultedAssocType;
5386+
return {Type(), nullptr};
53915387

5392-
return defaultType;
5388+
return {defaultType, defaultedAssocType};
53935389
};
53945390

53955391
for (auto *requirement : proto->getMembers()) {
@@ -5402,7 +5398,7 @@ void TypeChecker::inferDefaultWitnesses(ProtocolDecl *proto) {
54025398

54035399
if (auto assocType = dyn_cast<AssociatedTypeDecl>(valueDecl)) {
54045400
if (assocType->getOverriddenDecls().empty()) {
5405-
if (Type defaultType = findAssociatedTypeDefault(assocType))
5401+
if (Type defaultType = findAssociatedTypeDefault(assocType).first)
54065402
proto->setDefaultTypeWitness(assocType, defaultType);
54075403
}
54085404

@@ -5457,9 +5453,10 @@ void TypeChecker::inferDefaultWitnesses(ProtocolDecl *proto) {
54575453
}
54585454

54595455
// Dig out the default associated type definition.
5460-
AssociatedTypeDecl *defaultedAssocType = nullptr;
5461-
Type defaultAssocType = findAssociatedTypeDefault(assocType,
5462-
&defaultedAssocType);
5456+
AssociatedTypeDecl *defaultedAssocDecl = nullptr;
5457+
Type defaultAssocType;
5458+
std::tie(defaultAssocType, defaultedAssocDecl) =
5459+
findAssociatedTypeDefault(assocType);
54635460
if (!defaultAssocType)
54645461
continue;
54655462

@@ -5472,13 +5469,14 @@ void TypeChecker::inferDefaultWitnesses(ProtocolDecl *proto) {
54725469
if (conformance.isInvalid()) {
54735470
// Diagnose the lack of a conformance. This is potentially an ABI
54745471
// incompatibility.
5475-
diagnose(proto, diag::assoc_type_default_conformance_failed,
5476-
defaultAssocType, assocType->getFullName(), req.getFirstType(),
5477-
req.getSecondType());
5478-
diagnose(defaultedAssocType, diag::assoc_type_default_here,
5479-
assocType->getFullName(), defaultAssocType)
5480-
.highlight(
5481-
defaultedAssocType->getDefaultDefinitionTypeRepr()->getSourceRange());
5472+
proto->diagnose(diag::assoc_type_default_conformance_failed,
5473+
defaultAssocType, assocType->getFullName(),
5474+
req.getFirstType(), req.getSecondType());
5475+
defaultedAssocDecl
5476+
->diagnose(diag::assoc_type_default_here, assocType->getFullName(),
5477+
defaultAssocType)
5478+
.highlight(defaultedAssocDecl->getDefaultDefinitionTypeRepr()
5479+
->getSourceRange());
54825480

54835481
continue;
54845482
}

0 commit comments

Comments
 (0)