Skip to content

Commit 4c47de5

Browse files
committed
Swift: Add a few more test cases.
1 parent 5f8875f commit 4c47de5

File tree

3 files changed

+72
-14
lines changed

3 files changed

+72
-14
lines changed

swift/ql/test/library-tests/dataflow/flowsources/FlowSources.expected

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,25 @@
5555
| generics.swift:67:9:67:27 | call to source11() | external |
5656
| generics.swift:68:9:68:18 | .source12 | external |
5757
| generics.swift:69:9:69:27 | call to source13() | external |
58-
| generics.swift:88:9:88:15 | .source1 | external |
59-
| generics.swift:89:9:89:15 | .source2 | external |
60-
| generics.swift:90:9:90:14 | .source1 | external |
61-
| generics.swift:91:9:91:14 | .source2 | external |
62-
| generics.swift:92:9:92:15 | .source1 | external |
63-
| generics.swift:93:9:93:15 | .source2 | external |
64-
| generics.swift:112:9:112:15 | .source1 | external |
65-
| generics.swift:113:9:113:15 | .source2 | external |
66-
| generics.swift:114:9:114:14 | .source1 | external |
67-
| generics.swift:115:9:115:14 | .source2 | external |
68-
| generics.swift:116:9:116:15 | .source1 | external |
69-
| generics.swift:117:9:117:15 | .source2 | external |
58+
| generics.swift:93:9:93:15 | .source0 | external |
59+
| generics.swift:94:9:94:15 | .source1 | external |
60+
| generics.swift:95:9:95:15 | .source2 | external |
61+
| generics.swift:96:9:96:14 | .source0 | external |
62+
| generics.swift:97:9:97:14 | .source1 | external |
63+
| generics.swift:98:9:98:14 | .source2 | external |
64+
| generics.swift:99:9:99:15 | .source0 | external |
65+
| generics.swift:100:9:100:15 | .source1 | external |
66+
| generics.swift:101:9:101:15 | .source2 | external |
67+
| generics.swift:125:9:125:15 | .source0 | external |
68+
| generics.swift:126:9:126:15 | .source1 | external |
69+
| generics.swift:127:9:127:15 | .source2 | external |
70+
| generics.swift:128:9:128:14 | .source0 | external |
71+
| generics.swift:129:9:129:14 | .source1 | external |
72+
| generics.swift:130:9:130:14 | .source2 | external |
73+
| generics.swift:131:9:131:15 | .source0 | external |
74+
| generics.swift:132:9:132:15 | .source1 | external |
75+
| generics.swift:133:9:133:15 | .source2 | external |
76+
| generics.swift:162:9:162:22 | call to source2() | external |
7077
| nsdata.swift:18:17:18:40 | call to NSData.init(contentsOf:) | external |
7178
| nsdata.swift:19:17:19:53 | call to NSData.init(contentsOf:options:) | external |
7279
| string.swift:56:21:56:44 | call to String.init(contentsOf:) | external |

swift/ql/test/library-tests/dataflow/flowsources/FlowSources.ql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@ class CustomTestSourcesCsv extends SourceModelCsv {
2222
";MyDerived2;true;source11();;;ReturnValue;remote", ";MyDerived2;true;source12;;;;remote",
2323
";MyDerived2;true;source13();;;ReturnValue;remote",
2424
// ---
25+
";MyParentProtocol;true;source0;;;;remote",
2526
";MyProtocol;true;source1;;;;remote", ";MyProtocol;true;source2;;;;remote",
2627
// ---
28+
";MyParentProtocol2;true;source0;;;;remote",
2729
";MyProtocol2;true;source1;;;;remote", ";MyProtocol2;true;source2;;;;remote",
30+
// ---
31+
";MyProtocol3;true;source1();;;ReturnValue;remote", ";MyProtocol3;true;source2();;;ReturnValue;remote",
32+
";MyProtocol3;true;source3();;;ReturnValue;remote"
2833
]
2934
}
3035
}

swift/ql/test/library-tests/dataflow/flowsources/generics.swift

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ func useDerived(generic: MyGeneric<Int>, generic2: MyGeneric<Any>, derived: MyDe
7171

7272
// ---
7373

74-
protocol MyProtocol {
74+
protocol MyParentProtocol {
75+
var source0: Int { get }
76+
}
77+
78+
protocol MyProtocol : MyParentProtocol {
7579
var source1: Int { get }
7680
var source2: Int { get }
7781
}
@@ -81,21 +85,29 @@ class MyImpl<T> : MyProtocol {
8185
}
8286

8387
extension MyImpl {
88+
var source0: Int { get { return 0 } }
8489
var source2: Int { get { return 0 } }
8590
}
8691

8792
func useProtocol(proto: MyProtocol, impl: MyImpl<Int>, impl2: MyImpl<Any>) {
93+
_ = proto.source0 // SOURCE
8894
_ = proto.source1 // SOURCE
8995
_ = proto.source2 // SOURCE
96+
_ = impl.source0 // SOURCE
9097
_ = impl.source1 // SOURCE
9198
_ = impl.source2 // SOURCE
99+
_ = impl2.source0 // SOURCE
92100
_ = impl2.source1 // SOURCE
93101
_ = impl2.source2 // SOURCE
94102
}
95103

96104
// ---
97105

98-
protocol MyProtocol2 {
106+
protocol MyParentProtocol2 {
107+
var source0: Int { get }
108+
}
109+
110+
protocol MyProtocol2 : MyParentProtocol2 {
99111
var source1: Int { get }
100112
var source2: Int { get }
101113
}
@@ -105,14 +117,48 @@ class MyImpl2<T> {
105117
}
106118

107119
extension MyImpl2 : MyProtocol2 {
120+
var source0: Int { get { return 0 } }
108121
var source2: Int { get { return 0 } }
109122
}
110123

111124
func useProtocol2(proto: MyProtocol2, impl: MyImpl2<Int>, impl2: MyImpl2<Any>) {
125+
_ = proto.source0 // SOURCE
112126
_ = proto.source1 // SOURCE
113127
_ = proto.source2 // SOURCE
128+
_ = impl.source0 // SOURCE
114129
_ = impl.source1 // SOURCE
115130
_ = impl.source2 // SOURCE
131+
_ = impl2.source0 // SOURCE
116132
_ = impl2.source1 // SOURCE
117133
_ = impl2.source2 // SOURCE
118134
}
135+
136+
// ---
137+
138+
protocol MyProtocol3 {
139+
func source1() -> Int
140+
func source2() -> Int
141+
func source3() -> Int
142+
}
143+
144+
class MyParentClass3 {
145+
func source1() -> Int { return 0 }
146+
}
147+
148+
class MyClass3 : MyParentClass3 {
149+
func source2() -> Int { return 0 }
150+
func source3() -> Int { return 0 }
151+
}
152+
153+
extension MyClass3 : MyProtocol3 {
154+
}
155+
156+
class MyChildClass3: MyClass3 {
157+
override func source3() -> Int { return 0 }
158+
}
159+
160+
func useProtocol3(impl: MyChildClass3) {
161+
_ = impl.source1() // not a source (`MyProtocol3.source1` is the declared source and `MyParentClass3` doesn't extend it)
162+
_ = impl.source2() // SOURCE
163+
_ = impl.source3() // SOURCE [NOT DETECTED]
164+
}

0 commit comments

Comments
 (0)