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 { }
36
36
@available ( SwiftStdlib 5 . 8 , * )
37
37
extension MyCxxSequence : Sequence , IteratorProtocol { }
38
38
39
+ class SwiftLinkedList : ListNode {
40
+ typealias Element = Int
41
+ func next( ) -> Int ? { return nil }
42
+ }
43
+
39
44
if #available( SwiftStdlib 5 . 8 , * ) {
40
45
41
46
var WitnessTableTestSuite = TestSuite ( " Use foreign reference in a generic context " )
@@ -68,6 +73,10 @@ WitnessTableTestSuite.test("As an existential") {
68
73
expectEqual ( cast? . value, 0 )
69
74
expectEqual ( cast? . next ( ) ? . value, 1 )
70
75
expectEqual ( cast? . next ( ) ? . next ( ) ? . value, 2 )
76
+
77
+ let notACxxValue : any ListNode = SwiftLinkedList ( )
78
+ let invalidCast = notACxxValue as? CxxLinkedList
79
+ expectNil ( invalidCast)
71
80
}
72
81
73
82
}
You can’t perform that action at this time.
0 commit comments