Skip to content

Commit a2db4ed

Browse files
committed
add a Copyable catch-all for non-nominals
After filtering out aggregates when determining if a type is Copyable, its safe to say that a type is Copyable if its not a nominal. The only types that are not copyable at the moment are move-only nominals and tuples containing such types.
1 parent 6c7fc72 commit a2db4ed

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/AST/Module.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,11 @@ LookupConformanceInModuleRequest::evaluate(
16461646

16471647
auto nominal = type->getAnyNominal();
16481648

1649+
// If it's not a nominal, then it's safe to assume its copyable.
1650+
if (!nominal && protocol->isSpecificProtocol(KnownProtocolKind::Copyable)) {
1651+
return ProtocolConformanceRef(protocol);
1652+
}
1653+
16491654
// If we don't have a nominal type, there are no conformances.
16501655
if (!nominal || isa<ProtocolDecl>(nominal))
16511656
return ProtocolConformanceRef::forMissingOrInvalid(type, protocol);

test/Parse/type_parameter_packs.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,9 @@ func quux<each T: P>(_ x: repeat each T) {}
3232
func foobar<T, U, each V>(x: T, y: U, z: repeat each V) { }
3333
func foobaz<T, each U, V>(x: T, y: repeat each U, z: V) { }
3434
func fooqux<each T, each U, each V>(x: repeat each T, y: repeat each U, z: repeat each V) { }
35+
36+
// coverage to ensure a 'repeat each' type is considered Copyable
37+
func golden<Z>(_ z: Z) {}
38+
func hour<each T>(_ t: repeat each T) {
39+
golden(t)
40+
}

0 commit comments

Comments
 (0)