[CSSimplify] If pack type has holes - its shape is a hole

Propagating holes to the shape helps avoid spurious diagnostics
about same-shape requirement failures.

Resolves: rdar://107675464
This commit is contained in:
Pavel Yaskevich
2023-04-26 09:18:46 -07:00
committed by Pavel Yaskevich
parent 3006f55327
commit 0db67464da
2 changed files with 27 additions and 0 deletions

View File

@@ -13269,6 +13269,14 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyShapeOfConstraint(
return formUnsolved(); return formUnsolved();
} }
if (type1->hasPlaceholder()) {
if (!shouldAttemptFixes())
return SolutionKind::Error;
recordTypeVariablesAsHoles(type2);
return SolutionKind::Solved;
}
auto shape = type1->getReducedShape(); auto shape = type1->getReducedShape();
addConstraint(ConstraintKind::Bind, shape, type2, locator); addConstraint(ConstraintKind::Bind, shape, type2, locator);
return SolutionKind::Solved; return SolutionKind::Solved;

View File

@@ -50,8 +50,15 @@ protocol P {
var value: A { get } var value: A { get }
func f(_ self: Self) -> Self func f(_ self: Self) -> Self
func makeA() -> A
} }
extension P {
func makeA() -> [Self] { return [self] }
}
func outerArchetype<each T, U>(t: repeat each T, u: U) where repeat each T: P { func outerArchetype<each T, U>(t: repeat each T, u: U) where repeat each T: P {
let _: (repeat (each T.A, U)) = (repeat ((each t).value, u)) let _: (repeat (each T.A, U)) = (repeat ((each t).value, u))
} }
@@ -439,3 +446,15 @@ func test_partually_flattened_expansions() {
_ = S().fn(t: 1, "hi", u: false, 1.0) // Ok _ = S().fn(t: 1, "hi", u: false, 1.0) // Ok
_ = S<Int, String>().fn(t: 1, "hi", u: false, 1.0) // Ok _ = S<Int, String>().fn(t: 1, "hi", u: false, 1.0) // Ok
} }
// rdar://107675464 - misplaced `each` results in `type of expression is ambiguous without more context`
do {
func test_correct_each<each T: P>(_ value: repeat each T) -> (repeat each T.A) {
return (repeat (each value).makeA()) // Ok
}
func test_misplaced_each<each T: P>(_ value: repeat each T) -> (repeat each T.A) {
return (repeat each value.makeA())
// expected-error@-1 {{pack reference 'each T' can only appear in pack expansion}}
}
}