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 44
55import swift
66import codeql.swift.dataflow.DataFlow
7+ import codeql.swift.dataflow.ExternalFlow
78
89class TestConfiguration extends DataFlow:: Configuration {
910 TestConfiguration ( ) { this = "TestConfiguration" }
@@ -14,10 +15,17 @@ class TestConfiguration extends DataFlow::Configuration {
1415
1516 override predicate isSink ( DataFlow:: Node sink ) {
1617 exists ( CallExpr sinkCall |
17- sinkCall .getStaticTarget ( ) .getName ( ) = "sink(arg:)" and
18+ sinkCall .getStaticTarget ( ) .getName ( ) = [ "sink(arg:)" , "sink(opt:)" ] and
1819 sinkCall .getAnArgument ( ) .getExpr ( ) = sink .asExpr ( )
1920 )
2021 }
2122
2223 override int explorationLimit ( ) { result = 100 }
2324}
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() {
251251func test_property_wrapper( ) {
252252 @DidSetSource var x = 42
253253 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