Skip to content

Commit b8005fa

Browse files
committed
unified: Mention flattening behavior of 'try?'
1 parent 8708905 commit b8005fa

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

‎unified/ql/lib/codeql/unified/internal/dataflow/DataFlowPluginSwift.qll‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ private class SwiftDataFlowPlugin extends DataFlowPlugin {
3838
node2.isResultValue(expr)
3939
or
4040
expr.getOperator().(PrefixOperator).getValue() = "try?" and
41+
// TODO: preserve the value of some.0 if it is already stored in that
4142
node1.isResultValue(expr.getOperand()) and
4243
step.storeName("some.0") and
4344
node2.isResultValue(expr)

‎unified/ql/test/library-tests/dataflow/test.swift‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,14 @@ func t26() {
237237
opt!.0 = source("t26.1")
238238
sink(opt!.0) // $ MISSING: hasValueFlow=t26.1
239239
}
240+
241+
func t27() {
242+
func getOptional() throws -> String? {
243+
return Optional.some(source("t27.1"))
244+
}
245+
// TODO: try? should not double-wrap in Optional
246+
let x = try? getOptional()
247+
if let x {
248+
sink(x) // $ MISSING: hasValueFlow=t27.1
249+
}
250+
}

0 commit comments

Comments
 (0)