Skip to content

Commit e635dd3

Browse files
committed
Sema: Generic parameter packs cannot witness associated type requirements
1 parent fa1e17f commit e635dd3

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

lib/Sema/TypeCheckProtocolInference.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,10 @@ AssociatedTypeInference::computeAbstractTypeWitness(
923923
// If there is a generic parameter of the named type, use that.
924924
if (auto genericSig = dc->getGenericSignatureOfContext()) {
925925
for (auto gp : genericSig.getInnermostGenericParams()) {
926+
// Packs cannot witness associated type requirements.
927+
if (gp->isParameterPack())
928+
continue;
929+
926930
if (gp->getName() == assocType->getName())
927931
return AbstractTypeWitness(assocType, gp);
928932
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-feature VariadicGenerics
2+
3+
// Because of -enable-experimental-feature VariadicGenerics
4+
// REQUIRES: asserts
5+
6+
// Generic parameter packs cannot witness associated type requirements
7+
protocol HasAssoc {
8+
associatedtype A
9+
// expected-note@-1 {{protocol requires nested type 'A'; do you want to add it?}}
10+
}
11+
12+
struct HasPack<each A>: HasAssoc {}
13+
// expected-error@-1 {{type 'HasPack<repeat each A>' does not conform to protocol 'HasAssoc'}}
14+
15+
protocol P {}
16+
17+
protocol HasPackRequirements {
18+
func doStuff1<each U>(_ value: repeat each U) -> (repeat Array<each U>)
19+
func doStuff2<each U>(_ value: repeat each U) -> (repeat Array<each U>)
20+
}
21+
22+
extension HasPackRequirements {
23+
func doStuff1<each U>(_ value: repeat each U) -> (repeat Array<each U>) {
24+
return (repeat [each value])
25+
}
26+
}
27+
28+
struct ConformsPackRequirements<each T>: HasPackRequirements {
29+
func doStuff2<each U>(_ value: repeat each U) -> (repeat Array<each U>) {
30+
return (repeat [each value])
31+
}
32+
}
33+
34+

0 commit comments

Comments
 (0)