|
1 |
| -// RUN: %target-run-simple-swift | %FileCheck %s |
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: %target-build-swift -Onone %s -o %t/a.out |
| 3 | +// RUN: %target-run %t/a.out | %FileCheck --check-prefix CHECK --check-prefix CHECK-ONONE %s |
2 | 4 | // RUN: %target-build-swift -O %s -o %t/a.out.optimized
|
3 | 5 | // RUN: %target-codesign %t/a.out.optimized
|
4 | 6 | // RUN: %target-run %t/a.out.optimized | %FileCheck %s
|
@@ -131,6 +133,58 @@ anyClassToCOrE(C()).print() // CHECK: C!
|
131 | 133 | anyClassToCOrE(D()).print() // CHECK: D!
|
132 | 134 | anyClassToCOrE(X()).print() // CHECK: E!
|
133 | 135 |
|
| 136 | +protocol P {} |
| 137 | +struct PS: P {} |
| 138 | +enum PE: P {} |
| 139 | +class PC: P {} |
| 140 | +class PCSub: PC {} |
| 141 | + |
| 142 | +func nongenericAnyIsP(type: Any.Type) -> Bool { |
| 143 | + return type is P.Type |
| 144 | +} |
| 145 | +func nongenericAnyIsPAndAnyObject(type: Any.Type) -> Bool { |
| 146 | + return type is (P & AnyObject).Type |
| 147 | +} |
| 148 | +func nongenericAnyIsPAndPCSub(type: Any.Type) -> Bool { |
| 149 | + return type is (P & PCSub).Type |
| 150 | +} |
| 151 | +func genericAnyIs<T>(type: Any.Type, to: T.Type) -> Bool { |
| 152 | + return type is T.Type |
| 153 | +} |
| 154 | +// CHECK-LABEL: casting types to protocols with generics: |
| 155 | +print("casting types to protocols with generics:") |
| 156 | +print(nongenericAnyIsP(type: PS.self)) // CHECK: true |
| 157 | +print(genericAnyIs(type: PS.self, to: P.self)) // CHECK-ONONE: true |
| 158 | +print(nongenericAnyIsP(type: PE.self)) // CHECK: true |
| 159 | +print(genericAnyIs(type: PE.self, to: P.self)) // CHECK-ONONE: true |
| 160 | +print(nongenericAnyIsP(type: PC.self)) // CHECK: true |
| 161 | +print(genericAnyIs(type: PC.self, to: P.self)) // CHECK-ONONE: true |
| 162 | +print(nongenericAnyIsP(type: PCSub.self)) // CHECK: true |
| 163 | +print(genericAnyIs(type: PCSub.self, to: P.self)) // CHECK-ONONE: true |
| 164 | + |
| 165 | +// CHECK-LABEL: casting types to protocol & AnyObject existentials: |
| 166 | +print("casting types to protocol & AnyObject existentials:") |
| 167 | +print(nongenericAnyIsPAndAnyObject(type: PS.self)) // CHECK: false |
| 168 | +print(genericAnyIs(type: PS.self, to: (P & AnyObject).self)) // CHECK: false |
| 169 | +print(nongenericAnyIsPAndAnyObject(type: PE.self)) // CHECK: false |
| 170 | +print(genericAnyIs(type: PE.self, to: (P & AnyObject).self)) // CHECK: false |
| 171 | +print(nongenericAnyIsPAndAnyObject(type: PC.self)) // CHECK: true |
| 172 | +print(genericAnyIs(type: PC.self, to: (P & AnyObject).self)) // CHECK-ONONE: true |
| 173 | +print(nongenericAnyIsPAndAnyObject(type: PCSub.self)) // CHECK: true |
| 174 | +print(genericAnyIs(type: PCSub.self, to: (P & AnyObject).self)) // CHECK-ONONE: true |
| 175 | + |
| 176 | +// CHECK-LABEL: casting types to protocol & class existentials: |
| 177 | +print("casting types to protocol & class existentials:") |
| 178 | +print(nongenericAnyIsPAndPCSub(type: PS.self)) // CHECK: false |
| 179 | +print(genericAnyIs(type: PS.self, to: (P & PCSub).self)) // CHECK: false |
| 180 | +print(nongenericAnyIsPAndPCSub(type: PE.self)) // CHECK: false |
| 181 | +print(genericAnyIs(type: PE.self, to: (P & PCSub).self)) // CHECK: false |
| 182 | +//print(nongenericAnyIsPAndPCSub(type: PC.self)) // CHECK-SR-11565: false -- FIXME: reenable this when SR-11565 is fixed |
| 183 | +print(genericAnyIs(type: PC.self, to: (P & PCSub).self)) // CHECK: false |
| 184 | +print(nongenericAnyIsPAndPCSub(type: PCSub.self)) // CHECK: true |
| 185 | +print(genericAnyIs(type: PCSub.self, to: (P & PCSub).self)) // CHECK-ONONE: true |
| 186 | + |
| 187 | + |
134 | 188 | // CHECK-LABEL: type comparisons:
|
135 | 189 | print("type comparisons:\n")
|
136 | 190 | print(allMetasToAllMetas(Int.self, Int.self)) // CHECK: true
|
|
0 commit comments