Skip to content

Commit 1ee4d5b

Browse files
committed
Add a SILGen test for collection upcasts
1 parent 06ceb19 commit 1ee4d5b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/SILGen/collection_upcast.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,21 @@ func testSetUpcastBridged(_ set: Set<BridgedSwift>) {
108108
// CHECK-NOT: destroy_value [[SET]]
109109
let anyObjectSet = set as Set<NSObject>
110110
}
111+
112+
protocol P {
113+
func selfArrayUpcast() -> [Self]
114+
func selfDictionaryUpcast() -> [String : Self]
115+
}
116+
117+
// CHECK-LABEL: sil hidden [ossa] @$s17collection_upcast44testCollectionUpcastWithCovariantSelfErasure{{.*}}F
118+
// CHECK: bb0([[ARG:%0]] : $*P):
119+
func testCollectionUpcastWithCovariantSelfErasure(arg: P) {
120+
let array = arg.selfArrayUpcast() // [P]
121+
// CHECK: open_existential_addr immutable_access [[ARG]] : $*P to $*@opened([[N:".*"]]) P
122+
// CHECK: [[UPCAST_FN:%[0-9]+]] = function_ref @$ss15_arrayForceCast{{.*}}F
123+
// CHECK: apply [[UPCAST_FN]]<@opened([[N]]) P, P>(%{{[0-9]+}}) : $@convention(thin) <τ_0_0, τ_0_1> (@guaranteed Array<τ_0_0>) -> @owned Array<τ_0_1>
124+
let dictionary = arg.selfDictionaryUpcast() // [String : P]
125+
// CHECK: open_existential_addr immutable_access [[ARG]] : $*P to $*@opened([[N:".*"]]) P
126+
// CHECK: [[UPCAST_FN:%[0-9]+]] = function_ref @$ss17_dictionaryUpCast{{.*}}F
127+
// CHECK: apply [[UPCAST_FN]]<String, @opened([[N]]) P, String, P>(%{{[0-9]+}}) : $@convention(thin) <τ_0_0, τ_0_1, τ_0_2, τ_0_3 where τ_0_0 : Hashable, τ_0_2 : Hashable> (@guaranteed Dictionary<τ_0_0, τ_0_1>) -> @owned Dictionary<τ_0_2, τ_0_3>
128+
}

0 commit comments

Comments
 (0)