Skip to content

Commit f972ad8

Browse files
committed
Sema: Tweak shape mismatch fixes
1 parent 261c04c commit f972ad8

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
@@ -13531,33 +13531,34 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifySameShapeConstraint(
1353113531
auto argLoc =
1353213532
loc->castLastElementTo<LocatorPathElt::ApplyArgToParam>();
1353313533

13534-
if (type1->getAs<PackArchetypeType>() &&
13535-
type2->getAs<PackArchetypeType>())
13534+
if (type1->is<PackArchetypeType>() &&
13535+
type2->is<PackArchetypeType>())
1353613536
return recordShapeMismatchFix();
1353713537

13538-
auto argPack = type1->getAs<PackType>();
13539-
auto paramPack = type2->getAs<PackType>();
13540-
13541-
if (!(argPack && paramPack))
13542-
return SolutionKind::Error;
13538+
auto numArgs = (shape1->is<PackType>()
13539+
? shape1->castTo<PackType>()->getNumElements()
13540+
: 1);
13541+
auto numParams = (shape2->is<PackType>()
13542+
? shape2->castTo<PackType>()->getNumElements()
13543+
: 1);
1354313544

1354413545
// Tailed diagnostic to explode tuples.
1354513546
// FIXME: This is very similar to
1354613547
// 'cannot_convert_single_tuple_into_multiple_arguments'; can we emit
1354713548
// both of these in the same place?
13548-
if (argPack->getNumElements() == 1) {
13549-
if (argPack->getElementType(0)->is<TupleType>() &&
13550-
paramPack->getNumElements() >= 1) {
13549+
if (numArgs == 1) {
13550+
if (type1->is<TupleType>() &&
13551+
numParams >= 1) {
1355113552
return recordShapeFix(
1355213553
DestructureTupleToMatchPackExpansionParameter::create(
13553-
*this, paramPack, loc),
13554-
/*impact=*/2 * paramPack->getNumElements());
13554+
*this,
13555+
(type2->is<PackType>()
13556+
? type2->castTo<PackType>()
13557+
: PackType::getSingletonPackExpansion(type2)), loc),
13558+
/*impact=*/2 * numParams);
1355513559
}
1355613560
}
1355713561

13558-
auto numArgs = shape1->castTo<PackType>()->getNumElements();
13559-
auto numParams = shape2->castTo<PackType>()->getNumElements();
13560-
1356113562
// Drops `ApplyArgToParam` and left with `ApplyArgument`.
1356213563
path.pop_back();
1356313564

0 commit comments

Comments
 (0)