Skip to content

Commit a10c56b

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 536087d commit a10c56b

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
@@ -13280,6 +13280,14 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyShapeOfConstraint(
1328013280
return formUnsolved();
1328113281
}
1328213282

13283+
if (type1->hasPlaceholder()) {
13284+
if (!shouldAttemptFixes())
13285+
return SolutionKind::Error;
13286+
13287+
recordTypeVariablesAsHoles(type2);
13288+
return SolutionKind::Solved;
13289+
}
13290+
1328313291
auto shape = type1->getReducedShape();
1328413292
addConstraint(ConstraintKind::Bind, shape, type2, locator);
1328513293
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
}
@@ -428,3 +435,15 @@ func test_partually_flattened_expansions() {
428435
_ = S().fn(t: 1, "hi", u: false, 1.0) // Ok
429436
_ = S<Int, String>().fn(t: 1, "hi", u: false, 1.0) // Ok
430437
}
438+
439+
// rdar://107675464 - misplaced `each` results in `type of expression is ambiguous without more context`
440+
do {
441+
func test_correct_each<each T: P>(_ value: repeat each T) -> (repeat each T.A) {
442+
return (repeat (each value).makeA()) // Ok
443+
}
444+
445+
func test_misplaced_each<each T: P>(_ value: repeat each T) -> (repeat each T.A) {
446+
return (repeat each value.makeA())
447+
// expected-error@-1 {{pack reference 'each T' can only appear in pack expansion}}
448+
}
449+
}

0 commit comments

Comments
 (0)