File tree Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -4561,11 +4561,28 @@ bool TypeBase::hasSimpleTypeRepr() const {
45614561 }
45624562
45634563 case TypeKind::ProtocolComposition: {
4564- // 'Any', 'AnyObject' and single protocol compositions are simple
45654564 auto composition = cast<const ProtocolCompositionType>(this );
4565+
4566+ // A protocol composition is simple if its syntactic representation does not
4567+ // involve `&`. This is true if we have 'Any', 'AnyObject', or a single
4568+ // inverse requirement like `~Copyable`.
4569+
4570+ // All other protocol compositions contain at least two `&`-separated terms.
4571+
4572+ // Add each logical member Foo.
45664573 auto memberCount = composition->getMembers ().size ();
4574+
4575+ // And each inverse requirement ~Foo.
4576+ for (auto ip : composition->getInverses ()) {
4577+ (void ) ip;
4578+ ++memberCount;
4579+ }
4580+
4581+ // And finally, AnyObject.
45674582 if (composition->hasExplicitAnyObject ())
4568- return memberCount == 0 ;
4583+ ++memberCount;
4584+
4585+ // Almost always, this will be > 1.
45694586 return memberCount <= 1 ;
45704587 }
45714588
Original file line number Diff line number Diff line change @@ -46,3 +46,22 @@ public protocol ProtocolTypealias {
4646
4747// CHECK: public func dependentExistential<T>(value: (T) -> any main.P) where T : main.ProtocolTypealias
4848public func dependentExistential< T: ProtocolTypealias > ( value: ( T ) -> T . A ) { }
49+
50+ public protocol Yescopyable { }
51+ public protocol Noncopyable : ~ Copyable { }
52+
53+ // CHECK: public func existentialMetatype1(_: any (main.Noncopyable & ~Copyable).Type)
54+ // CHECK: public func existentialMetatype2(_: any (main.Noncopyable & main.Yescopyable).Type)
55+ // CHECK: public func existentialMetatype3(_: any ~Copyable.Type)
56+
57+ public func existentialMetatype1( _: any ( Noncopyable & ~ Copyable) . Type) { }
58+ public func existentialMetatype2( _: any ( Yescopyable & Noncopyable ) . Type) { }
59+ public func existentialMetatype3( _: any ~ Copyable. Type) { }
60+
61+ // CHECK: public func metatypeExistential1(_: (any main.Noncopyable & ~Copyable).Type)
62+ // CHECK: public func metatypeExistential2(_: (any main.Noncopyable & main.Yescopyable).Type)
63+ // CHECK: public func metatypeExistential3(_: (any ~Copyable).Type)
64+
65+ public func metatypeExistential1( _: ( any Noncopyable & ~ Copyable) . Type) { }
66+ public func metatypeExistential2( _: ( any Yescopyable & Noncopyable ) . Type) { }
67+ public func metatypeExistential3( _: ( any ~ Copyable) . Type) { }
You can’t perform that action at this time.
0 commit comments