Skip to content

Commit 5a5edca

Browse files
committed
[CSSimplify] Extend same-shape detection to account for pack archetypes
`same-shape` mismatch detection logic shouldn't expect that types are always packs because they could be either invalid (i.e. Void) or pack archetypes too. Resolves: rdar://112090069
1 parent aad2b6e commit 5a5edca

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13479,6 +13479,17 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifySameShapeConstraint(
1347913479
: SolutionKind::Solved;
1348013480
};
1348113481

13482+
auto recordShapeMismatchFix = [&]() -> SolutionKind {
13483+
unsigned impact = 1;
13484+
if (locator.endsWith<LocatorPathElt::AnyRequirement>())
13485+
impact = assessRequirementFailureImpact(*this, shape1, locator);
13486+
13487+
return recordShapeFix(
13488+
SkipSameShapeRequirement::create(*this, type1, type2,
13489+
getConstraintLocator(locator)),
13490+
impact);
13491+
};
13492+
1348213493
// Let's check whether we can produce a tailored fix for argument/parameter
1348313494
// mismatches.
1348413495
if (locator.endsWith<LocatorPathElt::PackShape>()) {
@@ -13498,8 +13509,15 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifySameShapeConstraint(
1349813509
auto argLoc =
1349913510
loc->castLastElementTo<LocatorPathElt::ApplyArgToParam>();
1350013511

13501-
auto argPack = type1->castTo<PackType>();
13502-
auto paramPack = type2->castTo<PackType>();
13512+
if (type1->getAs<PackArchetypeType>() &&
13513+
type2->getAs<PackArchetypeType>())
13514+
return recordShapeMismatchFix();
13515+
13516+
auto argPack = type1->getAs<PackType>();
13517+
auto paramPack = type2->getAs<PackType>();
13518+
13519+
if (!(argPack && paramPack))
13520+
return SolutionKind::Error;
1350313521

1350413522
// Tailed diagnostic to explode tuples.
1350513523
// FIXME: This is very similar to
@@ -13558,14 +13576,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifySameShapeConstraint(
1355813576
}
1355913577
}
1356013578

13561-
unsigned impact = 1;
13562-
if (locator.endsWith<LocatorPathElt::AnyRequirement>())
13563-
impact = assessRequirementFailureImpact(*this, shape1, locator);
13564-
13565-
return recordShapeFix(
13566-
SkipSameShapeRequirement::create(*this, type1, type2,
13567-
getConstraintLocator(locator)),
13568-
impact);
13579+
return recordShapeMismatchFix();
1356913580
}
1357013581

1357113582
return SolutionKind::Error;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-typecheck-verify-swift -disable-availability-checking
2+
3+
func test<each Before,
4+
each At,
5+
each After,
6+
each Return>(
7+
_ fn: (repeat each Before, repeat each At, repeat each After) -> (repeat each Return),
8+
at: repeat each At) -> (repeat each Before, repeat each After) -> (repeat each Return) {
9+
return { (before: repeat each Before, after: repeat each After) in // expected-error {{no parameters may follow a variadic parameter in a closure}}
10+
return fn(repeat each before, repeat each at, repeat each after)
11+
// expected-error@-1 {{pack expansion requires that 'each At' and 'each Before' have the same shape}}
12+
// expected-error@-2 {{cannot convert value of type 'each At' to expected argument type 'each Before'}}
13+
// expected-error@-3 {{pack expansion requires that 'each After' and 'each Before' have the same shape}}
14+
// expected-error@-4 {{cannot convert value of type 'each After' to expected argument type 'each Before'}}
15+
}
16+
}

0 commit comments

Comments
 (0)