Skip to content

Commit 33a37b9

Browse files
authored
Merge pull request #67377 from xedin/rdar-112090069
[CSSimplify] Extend same-shape detection to account for pack archetypes
2 parents 31d1c4c + 5a5edca commit 33a37b9

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
@@ -13499,6 +13499,17 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifySameShapeConstraint(
1349913499
: SolutionKind::Solved;
1350013500
};
1350113501

13502+
auto recordShapeMismatchFix = [&]() -> SolutionKind {
13503+
unsigned impact = 1;
13504+
if (locator.endsWith<LocatorPathElt::AnyRequirement>())
13505+
impact = assessRequirementFailureImpact(*this, shape1, locator);
13506+
13507+
return recordShapeFix(
13508+
SkipSameShapeRequirement::create(*this, type1, type2,
13509+
getConstraintLocator(locator)),
13510+
impact);
13511+
};
13512+
1350213513
// Let's check whether we can produce a tailored fix for argument/parameter
1350313514
// mismatches.
1350413515
if (locator.endsWith<LocatorPathElt::PackShape>()) {
@@ -13518,8 +13529,15 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifySameShapeConstraint(
1351813529
auto argLoc =
1351913530
loc->castLastElementTo<LocatorPathElt::ApplyArgToParam>();
1352013531

13521-
auto argPack = type1->castTo<PackType>();
13522-
auto paramPack = type2->castTo<PackType>();
13532+
if (type1->getAs<PackArchetypeType>() &&
13533+
type2->getAs<PackArchetypeType>())
13534+
return recordShapeMismatchFix();
13535+
13536+
auto argPack = type1->getAs<PackType>();
13537+
auto paramPack = type2->getAs<PackType>();
13538+
13539+
if (!(argPack && paramPack))
13540+
return SolutionKind::Error;
1352313541

1352413542
// Tailed diagnostic to explode tuples.
1352513543
// FIXME: This is very similar to
@@ -13578,14 +13596,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifySameShapeConstraint(
1357813596
}
1357913597
}
1358013598

13581-
unsigned impact = 1;
13582-
if (locator.endsWith<LocatorPathElt::AnyRequirement>())
13583-
impact = assessRequirementFailureImpact(*this, shape1, locator);
13584-
13585-
return recordShapeFix(
13586-
SkipSameShapeRequirement::create(*this, type1, type2,
13587-
getConstraintLocator(locator)),
13588-
impact);
13599+
return recordShapeMismatchFix();
1358913600
}
1359013601

1359113602
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)