File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed
swift/ql/test/library-tests/dataflow/dataflow Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change 4
4
5
5
import swift
6
6
import codeql.swift.dataflow.DataFlow
7
+ import codeql.swift.dataflow.ExternalFlow
7
8
8
9
class TestConfiguration extends DataFlow:: Configuration {
9
10
TestConfiguration ( ) { this = "TestConfiguration" }
@@ -14,10 +15,17 @@ class TestConfiguration extends DataFlow::Configuration {
14
15
15
16
override predicate isSink ( DataFlow:: Node sink ) {
16
17
exists ( CallExpr sinkCall |
17
- sinkCall .getStaticTarget ( ) .getName ( ) = "sink(arg:)" and
18
+ sinkCall .getStaticTarget ( ) .getName ( ) = [ "sink(arg:)" , "sink(opt:)" ] and
18
19
sinkCall .getAnArgument ( ) .getExpr ( ) = sink .asExpr ( )
19
20
)
20
21
}
21
22
22
23
override int explorationLimit ( ) { result = 100 }
23
24
}
25
+
26
+ private class TestSummaries extends SummaryModelCsv {
27
+ override predicate row ( string row ) {
28
+ // dumb model to allow testing flow through optional chaining (`x?.signum()`)
29
+ row = ";Int;true;signum();;;Argument[-1];ReturnValue;value"
30
+ }
31
+ }
Original file line number Diff line number Diff line change @@ -251,4 +251,21 @@ func test_computed_property() {
251
251
func test_property_wrapper( ) {
252
252
@DidSetSource var x = 42
253
253
sink ( arg: x) // $ MISSING: flow=243
254
- }
254
+ }
255
+
256
+ func sink( opt: Int ? ) { }
257
+
258
+ func optionalSource( ) -> Int ? {
259
+ return source ( )
260
+ }
261
+
262
+ func test_optionals( ) {
263
+ let x = optionalSource ( )
264
+ sink ( arg: x!) // $ flow=259
265
+ sink ( arg: source ( ) . signum ( ) ) // $ MISSING: flow=259
266
+ sink ( opt: x? . signum ( ) ) // $ MISSING: flow=259
267
+ sink ( arg: x ?? 0 ) // $ MISSING: flow=259
268
+ if let y = x {
269
+ sink ( arg: y) // $ MISSING: flow=259
270
+ }
271
+ }
You can’t perform that action at this time.
0 commit comments