Skip to content

Commit ea1924f

Browse files
committed
ensure exisentials are copyable
1 parent a0d4dd7 commit ea1924f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/AST/Module.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,13 @@ ModuleDecl::lookupExistentialConformance(Type type, ProtocolDecl *protocol) {
11781178
if (!protocol->existentialConformsToSelf())
11791179
return ProtocolConformanceRef::forInvalid();
11801180

1181+
// All existentials are Copyable.
1182+
if (protocol->isSpecificProtocol(KnownProtocolKind::Copyable)) {
1183+
return ProtocolConformanceRef(
1184+
ctx.getBuiltinConformance(type, protocol, GenericSignature(), {},
1185+
BuiltinConformanceKind::Synthesized));
1186+
}
1187+
11811188
auto layout = type->getExistentialLayout();
11821189

11831190
// Due to an IRGen limitation, witness tables cannot be passed from an

test/Constraints/moveonly_constraints.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ func checkStdlibTypes(_ mo: MO) {
164164
let s: String = "hello \(mo)" // expected-error {{move-only type 'MO' cannot be used with generics yet}}
165165
}
166166

167+
func copyableExistentials(_ a: Any, _ e1: Error, _ e2: any Error, _ ah: AnyHashable) {
168+
takeGeneric(a)
169+
takeGeneric(e1)
170+
takeGeneric(e2)
171+
takeGeneric(ah)
172+
}
173+
167174
// ensure that associated types can't be witnessed by move-only types
168175

169176
protocol HasType<Ty> {

0 commit comments

Comments
 (0)