File tree Expand file tree Collapse file tree 1 file changed +24
-3
lines changed
swift/ql/lib/codeql/swift/dataflow/internal Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -942,7 +942,30 @@ private module CaptureInput implements VariableCapture::InputSig {
942
942
}
943
943
944
944
class Callable extends S:: Callable {
945
- predicate isConstructor ( ) { this instanceof S:: Initializer }
945
+ predicate isConstructor ( ) {
946
+ // A class declaration cannot capture a variable in Swift. Consider this hypothetical example:
947
+ // ```
948
+ // protocol Interface { }
949
+ // func foo() -> Interface {
950
+ // let y = 42
951
+ // class Impl : Interface {
952
+ // let x : Int
953
+ // init() {
954
+ // x = y
955
+ // }
956
+ // }
957
+ // let object = Impl()
958
+ // return object
959
+ // }
960
+ // ```
961
+ // The Swift compiler will reject this with an error message such as
962
+ // ```
963
+ // error: class declaration cannot close over value 'y' defined in outer scope
964
+ // x = y
965
+ // ^
966
+ // ```
967
+ none ( )
968
+ }
946
969
}
947
970
}
948
971
@@ -964,8 +987,6 @@ private CaptureFlow::ClosureNode asClosureNode(Node n) {
964
987
or
965
988
result .( CaptureFlow:: ThisParameterNode ) .getCallable ( ) = n .( ClosureSelfParameterNode ) .getClosure ( )
966
989
or
967
- result .( CaptureFlow:: MallocNode ) .getClosureExpr ( ) = n .getCfgNode ( ) .getNode ( ) .asAstNode ( ) // TODO: figure out why the java version had PostUpdateNode logic here
968
- or
969
990
exists ( CaptureInput:: VariableWrite write |
970
991
result .( CaptureFlow:: VariableWriteSourceNode ) .getVariableWrite ( ) = write and
971
992
n .asExpr ( ) = write .getSource ( )
You can’t perform that action at this time.
0 commit comments