Skip to content

Commit 0db6746

Browse files
committed
[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
1 parent 3006f55 commit 0db6746

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13269,6 +13269,14 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyShapeOfConstraint(
1326913269
return formUnsolved();
1327013270
}
1327113271

13272+
if (type1->hasPlaceholder()) {
13273+
if (!shouldAttemptFixes())
13274+
return SolutionKind::Error;
13275+
13276+
recordTypeVariablesAsHoles(type2);
13277+
return SolutionKind::Solved;
13278+
}
13279+
1327213280
auto shape = type1->getReducedShape();
1327313281
addConstraint(ConstraintKind::Bind, shape, type2, locator);
1327413282
return SolutionKind::Solved;

test/Constraints/pack-expansion-expressions.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,15 @@ protocol P {
5050
var value: A { get }
5151

5252
func f(_ self: Self) -> Self
53+
54+
func makeA() -> A
55+
}
56+
57+
extension P {
58+
func makeA() -> [Self] { return [self] }
5359
}
5460

61+
5562
func outerArchetype<each T, U>(t: repeat each T, u: U) where repeat each T: P {
5663
let _: (repeat (each T.A, U)) = (repeat ((each t).value, u))
5764
}
@@ -439,3 +446,15 @@ func test_partually_flattened_expansions() {
439446
_ = S().fn(t: 1, "hi", u: false, 1.0) // Ok
440447
_ = S<Int, String>().fn(t: 1, "hi", u: false, 1.0) // Ok
441448
}
449+
450+
// rdar://107675464 - misplaced `each` results in `type of expression is ambiguous without more context`
451+
do {
452+
func test_correct_each<each T: P>(_ value: repeat each T) -> (repeat each T.A) {
453+
return (repeat (each value).makeA()) // Ok
454+
}
455+
456+
func test_misplaced_each<each T: P>(_ value: repeat each T) -> (repeat each T.A) {
457+
return (repeat each value.makeA())
458+
// expected-error@-1 {{pack reference 'each T' can only appear in pack expansion}}
459+
}
460+
}

0 commit comments

Comments
 (0)