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 {
4561
4561
}
4562
4562
4563
4563
case TypeKind::ProtocolComposition: {
4564
- // 'Any', 'AnyObject' and single protocol compositions are simple
4565
4564
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.
4566
4573
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.
4567
4582
if (composition->hasExplicitAnyObject ())
4568
- return memberCount == 0 ;
4583
+ ++memberCount;
4584
+
4585
+ // Almost always, this will be > 1.
4569
4586
return memberCount <= 1 ;
4570
4587
}
4571
4588
Original file line number Diff line number Diff line change @@ -46,3 +46,22 @@ public protocol ProtocolTypealias {
46
46
47
47
// CHECK: public func dependentExistential<T>(value: (T) -> any main.P) where T : main.ProtocolTypealias
48
48
public 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