File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
test/Interop/Cxx/foreign-reference Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 1+ // RUN: %target-typecheck-verify-swift -cxx-interoperability-mode=default -disable-availability-checking -I %S/Inputs
2+
3+ import WitnessTable
4+
5+ public protocol ListNode {
6+ associatedtype Element
7+ func next( ) -> Element ?
8+ }
9+
10+ @available ( SwiftStdlib 5 . 8 , * )
11+ extension CxxLinkedList : ListNode { }
12+
13+ let existential : any ListNode = makeLinkedList ( )
14+ let cast : CxxLinkedList ? = existential as? CxxLinkedList
Original file line number Diff line number Diff line change @@ -36,6 +36,11 @@ extension CxxLinkedList : ListNode { }
3636@available ( SwiftStdlib 5 . 8 , * )
3737extension MyCxxSequence : Sequence , IteratorProtocol { }
3838
39+ class SwiftLinkedList : ListNode {
40+ typealias Element = Int
41+ func next( ) -> Int ? { return nil }
42+ }
43+
3944if #available( SwiftStdlib 5 . 8 , * ) {
4045
4146var WitnessTableTestSuite = TestSuite ( " Use foreign reference in a generic context " )
@@ -68,6 +73,10 @@ WitnessTableTestSuite.test("As an existential") {
6873 expectEqual ( cast? . value, 0 )
6974 expectEqual ( cast? . next ( ) ? . value, 1 )
7075 expectEqual ( cast? . next ( ) ? . next ( ) ? . value, 2 )
76+
77+ let notACxxValue : any ListNode = SwiftLinkedList ( )
78+ let invalidCast = notACxxValue as? CxxLinkedList
79+ expectNil ( invalidCast)
7180}
7281
7382}
You can’t perform that action at this time.
0 commit comments