Skip to content

Commit 08231bf

Browse files
committed
add a Copyable conformance for PackExpansionType
1 parent 1f85ad2 commit 08231bf

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/AST/Module.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,6 +1724,16 @@ LookupConformanceInModuleRequest::evaluate(
17241724
return getBuiltinBuiltinTypeConformance(type, builtinType, protocol);
17251725
}
17261726

1727+
// Specific handling of Copyable for pack expansions.
1728+
if (auto packExpansion = type->getAs<PackExpansionType>()) {
1729+
if (protocol->isSpecificProtocol(KnownProtocolKind::Copyable)) {
1730+
auto patternType = packExpansion->getPatternType();
1731+
return (patternType->isTypeParameter()
1732+
? ProtocolConformanceRef(protocol)
1733+
: mod->lookupConformance(patternType, protocol));
1734+
}
1735+
}
1736+
17271737
auto nominal = type->getAnyNominal();
17281738

17291739
// If we don't have a nominal type, there are no conformances.

test/type/pack_expansion.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,9 @@ func invalidPackRef(_: each Int) {}
7474

7575
// expected-error@+1 {{pack reference 'T' can only appear in pack expansion or generic requirement}}
7676
func packRefOutsideExpansion<each T>(_: each T) {}
77+
78+
// coverage to ensure a 'repeat each' type is considered Copyable
79+
func golden<Z>(_ z: Z) {}
80+
func hour<each T>(_ t: repeat each T) {
81+
_ = repeat golden(each t)
82+
}

0 commit comments

Comments
 (0)