Skip to content

Commit 9597f54

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 (cherry picked from commit 0db6746)
1 parent 998ae86 commit 9597f54

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
@@ -13274,6 +13274,14 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyShapeOfConstraint(
1327413274
return formUnsolved();
1327513275
}
1327613276

13277+
if (type1->hasPlaceholder()) {
13278+
if (!shouldAttemptFixes())
13279+
return SolutionKind::Error;
13280+
13281+
recordTypeVariablesAsHoles(type2);
13282+
return SolutionKind::Solved;
13283+
}
13284+
1327713285
auto shape = type1->getReducedShape();
1327813286
addConstraint(ConstraintKind::Bind, shape, type2, locator);
1327913287
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
}
@@ -438,3 +445,15 @@ func test_partually_flattened_expansions() {
438445
_ = S().fn(t: 1, "hi", u: false, 1.0) // Ok
439446
_ = S<Int, String>().fn(t: 1, "hi", u: false, 1.0) // Ok
440447
}
448+
449+
// rdar://107675464 - misplaced `each` results in `type of expression is ambiguous without more context`
450+
do {
451+
func test_correct_each<each T: P>(_ value: repeat each T) -> (repeat each T.A) {
452+
return (repeat (each value).makeA()) // Ok
453+
}
454+
455+
func test_misplaced_each<each T: P>(_ value: repeat each T) -> (repeat each T.A) {
456+
return (repeat each value.makeA())
457+
// expected-error@-1 {{pack reference 'each T' can only appear in pack expansion}}
458+
}
459+
}

0 commit comments

Comments
 (0)