mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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:
committed by
Pavel Yaskevich
parent
3006f55327
commit
0db67464da
@@ -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;
|
||||||
|
|||||||
@@ -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}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user