@@ -290,28 +290,56 @@ public func testReabstracted(f: Optional<()->()>) {
290290}
291291
292292
293- // Test that we don't devirtualize calls to protocol requirements with covariant `Self` nested
294- // inside a collection type – the devirtualizer does not support handling these yet.
295- protocol CovariantSelfInsideCollection {
296- func array( ) -> Array < Self >
297- func dictionary( ) -> Dictionary < String , Self >
298- func mixed( _: ( Array < ( Dictionary < String , String > , Self ) > ) -> Void )
293+ // Test that we don't devirtualize calls to protocol requirements with
294+ // covariant `Self`-rooted type parameters nested inside a collection type;
295+ // the devirtualizer doesn't know how to handle these yet.
296+ protocol CovariantSelfInCollection {
297+ associatedtype Assoc
298+
299+ func self1( ) -> Array < Self >
300+ func self2( ) -> Dictionary < String , Self >
301+ func self3( _: ( Self . . . ) -> Void )
302+ func self4( _: ( Array < ( Dictionary < String , String > , Self ) > ) -> Void )
303+
304+ func assoc1( ) -> Array < Assoc >
305+ func assoc2( ) -> Dictionary < String , Assoc >
306+ func assoc3( _: ( Assoc . . . ) -> Void )
307+ func assoc4( _: ( Array < ( Dictionary < String , String > , Assoc ) > ) -> Void )
308+ }
309+ struct CovariantSelfInCollectionImpl : CovariantSelfInCollection {
310+ typealias Assoc = Bool
311+
312+ func self1( ) -> Array < Self > { [ self ] }
313+ func self2( ) -> Dictionary < String , Self > { [ #file : self ] }
314+ func self3( _: ( Self . . . ) -> Void ) { }
315+ func self4( _: ( Array < ( Dictionary < String , String > , Self ) > ) -> Void ) { }
316+
317+ func assoc1( ) -> Array < Assoc > { [ true ] }
318+ func assoc2( ) -> Dictionary < String , Assoc > { [ #file : true ] }
319+ func assoc3( _: ( Assoc . . . ) -> Void ) { }
320+ func assoc4( _: ( Array < ( Dictionary < String , String > , Assoc ) > ) -> Void ) { }
299321}
300322// CHECK-LABEL: sil @$s34devirt_protocol_method_invocations12testNoDevirtyyF
301323//
302- // CHECK: witness_method $S, #CovariantSelfInsideCollection.array
303- // CHECK: witness_method $S, #CovariantSelfInsideCollection.dictionary
304- // CHECK: witness_method $S, #CovariantSelfInsideCollection.mixed
324+ // CHECK: witness_method $CovariantSelfInCollectionImpl, #CovariantSelfInCollection.self1
325+ // CHECK: witness_method $CovariantSelfInCollectionImpl, #CovariantSelfInCollection.self2
326+ // CHECK: witness_method $CovariantSelfInCollectionImpl, #CovariantSelfInCollection.self3
327+ // CHECK: witness_method $CovariantSelfInCollectionImpl, #CovariantSelfInCollection.self4
328+ // CHECK: witness_method $CovariantSelfInCollectionImpl, #CovariantSelfInCollection.assoc1
329+ // CHECK: witness_method $CovariantSelfInCollectionImpl, #CovariantSelfInCollection.assoc2
330+ // CHECK: witness_method $CovariantSelfInCollectionImpl, #CovariantSelfInCollection.assoc3
331+ // CHECK: witness_method $CovariantSelfInCollectionImpl, #CovariantSelfInCollection.assoc4
305332// CHECK: end sil function '$s34devirt_protocol_method_invocations12testNoDevirtyyF'
306333public func testNoDevirt( ) {
307- struct S : CovariantSelfInsideCollection {
308- func array( ) -> Array < Self > { fatalError ( ) }
309- func dictionary( ) -> Dictionary < String , Self > { fatalError ( ) }
310- func mixed( _: ( Array < ( Dictionary < String , String > , Self ) > ) -> Void ) { }
311- }
334+ let p : any CovariantSelfInCollection = CovariantSelfInCollectionImpl ( )
335+
336+ _ = p. self1 ( )
337+ _ = p. self2 ( )
338+ p. self3 { _ in }
339+ p. self4 { _ in }
312340
313- let p : CovariantSelfInsideCollection = S ( )
314- _ = p. array ( )
315- _ = p . dictionary ( )
316- p. mixed { _ in }
341+ _ = p . assoc1 ( )
342+ _ = p. assoc2 ( )
343+ p . assoc3 { _ in }
344+ p. assoc4 { _ in }
317345}
0 commit comments