File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -767,4 +767,29 @@ ErrorBridgingTests.test("@objc error domains for nested types") {
767
767
String ( reflecting: NonPrintAsObjCError . self) )
768
768
}
769
769
770
+ @inline ( never)
771
+ @_optimize ( none)
772
+ func anyToAny< T, U> ( _ a: T , _ : U . Type ) -> U {
773
+ return a as! U
774
+ }
775
+
776
+ ErrorBridgingTests . test ( " error-to-NSObject casts " ) {
777
+ let error = MyCustomizedError ( code: 12345 )
778
+
779
+ // Unconditional cast
780
+ let nsErrorAsObject1 = unconditionalCast ( error, to: NSObject . self)
781
+ let nsError1 = unconditionalCast ( nsErrorAsObject1, to: NSError . self)
782
+ expectEqual ( " custom " , nsError1. domain)
783
+ expectEqual ( 12345 , nsError1. code)
784
+
785
+ // Conditional cast
786
+ let nsErrorAsObject2 = conditionalCast ( error, to: NSObject . self) !
787
+ let nsError2 = unconditionalCast ( nsErrorAsObject2, to: NSError . self)
788
+ expectEqual ( " custom " , nsError2. domain)
789
+ expectEqual ( 12345 , nsError2. code)
790
+
791
+ // "is" check
792
+ expectTrue ( error is NSObject )
793
+ }
794
+
770
795
runAllTests ( )
You can’t perform that action at this time.
0 commit comments