Skip to content

Commit 94c295e

Browse files
committed
Sema: Tweak shape mismatch fixes
1 parent ddbb8c5 commit 94c295e

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13624,33 +13624,34 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifySameShapeConstraint(
1362413624
auto argLoc =
1362513625
loc->castLastElementTo<LocatorPathElt::ApplyArgToParam>();
1362613626

13627-
if (type1->getAs<PackArchetypeType>() &&
13628-
type2->getAs<PackArchetypeType>())
13627+
if (type1->is<PackArchetypeType>() &&
13628+
type2->is<PackArchetypeType>())
1362913629
return recordShapeMismatchFix();
1363013630

13631-
auto argPack = type1->getAs<PackType>();
13632-
auto paramPack = type2->getAs<PackType>();
13633-
13634-
if (!(argPack && paramPack))
13635-
return SolutionKind::Error;
13631+
auto numArgs = (shape1->is<PackType>()
13632+
? shape1->castTo<PackType>()->getNumElements()
13633+
: 1);
13634+
auto numParams = (shape2->is<PackType>()
13635+
? shape2->castTo<PackType>()->getNumElements()
13636+
: 1);
1363613637

1363713638
// Tailed diagnostic to explode tuples.
1363813639
// FIXME: This is very similar to
1363913640
// 'cannot_convert_single_tuple_into_multiple_arguments'; can we emit
1364013641
// both of these in the same place?
13641-
if (argPack->getNumElements() == 1) {
13642-
if (argPack->getElementType(0)->is<TupleType>() &&
13643-
paramPack->getNumElements() >= 1) {
13642+
if (numArgs == 1) {
13643+
if (type1->is<TupleType>() &&
13644+
numParams >= 1) {
1364413645
return recordShapeFix(
1364513646
DestructureTupleToMatchPackExpansionParameter::create(
13646-
*this, paramPack, loc),
13647-
/*impact=*/2 * paramPack->getNumElements());
13647+
*this,
13648+
(type2->is<PackType>()
13649+
? type2->castTo<PackType>()
13650+
: PackType::getSingletonPackExpansion(type2)), loc),
13651+
/*impact=*/2 * numParams);
1364813652
}
1364913653
}
1365013654

13651-
auto numArgs = shape1->castTo<PackType>()->getNumElements();
13652-
auto numParams = shape2->castTo<PackType>()->getNumElements();
13653-
1365413655
// Drops `ApplyArgToParam` and left with `ApplyArgument`.
1365513656
path.pop_back();
1365613657

0 commit comments

Comments
 (0)