Skip to content

Commit fe6cfe2

Browse files
committed
[CSDiagnostics] Diagnose conformance failures related to pack expansion patterns
1 parent 1e03cdc commit fe6cfe2

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8356,6 +8356,13 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
83568356
if (path.back().is<LocatorPathElt::PackElement>())
83578357
path.pop_back();
83588358

8359+
// This is similar to `PackElement` but locator points to the requirement
8360+
// associted with pack expansion pattern (i.e. `repeat each T: P`) where
8361+
// the path is something like:
8362+
// `... -> type req # -> pack expansion pattern`.
8363+
if (path.back().is<LocatorPathElt::PackExpansionPattern>())
8364+
path.pop_back();
8365+
83598366
if (auto req = path.back().getAs<LocatorPathElt::AnyRequirement>()) {
83608367
// If this is a requirement associated with `Self` which is bound
83618368
// to `Any`, let's consider this "too incorrect" to continue.

test/Constraints/pack-expansion-expressions.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,10 @@ func test_pack_expansion_to_void_conv_for_closure_result<each T>(x: repeat each
532532
// rdar://109539394 - crash on passing multiple variadic lists to singly variadic callee
533533
do {
534534
func test1<each T>(_: repeat each T) {}
535+
func test2<each T>(_: repeat each T) where repeat each T: RawRepresentable {} // expected-note {{where 'each T' = 'each T2'}}
535536

536537
func caller<each T1, each T2>(t1: repeat each T1, t2: repeat each T2) {
537538
test1(repeat each t1, repeat each t2) // Ok
539+
test2(repeat each t2, repeat each t1) // expected-error {{local function 'test2' requires that 'each T2' conform to 'RawRepresentable'}}
538540
}
539541
}

0 commit comments

Comments
 (0)