File tree Expand file tree Collapse file tree
lib/codeql/unified/internal
test/library-tests/local-name-binding Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -168,6 +168,11 @@ private module LocalNameBindingInput implements LocalNameBindingInputSig<Locatio
168168
169169 private class LocalVariableDeclarationSiblingShadowingDecl extends SiblingShadowingDecl instanceof LocalVariableDeclaration
170170 {
171+ LocalVariableDeclarationSiblingShadowingDecl ( ) {
172+ // Capture-declarations act as local variables, but are not sibling-shadowing
173+ not this = any ( FunctionExpr e ) .getACaptureDeclaration ( )
174+ }
175+
171176 override Expr getPattern ( ) { result = LocalVariableDeclaration .super .getPattern ( ) }
172177
173178 override AstNode getRhs ( ) { result = LocalVariableDeclaration .super .getValue ( ) }
Original file line number Diff line number Diff line change 1+ class C {
2+ func t1( ) { // implicit-self=t1.self
3+ print ( self ) // $ access=t1.self
4+ }
5+
6+ var instanceField = 123 ;
7+
8+ func t2( ) { // implicit-self=t2.self
9+ print ( instanceField) // $ access=instanceField implicit-qualifier=t2.self
10+ }
11+
12+ func t3( ) { // implicit-self=t3.self
13+ foo ( 123 ) { [ self ] in // name=closure.self
14+ print ( self ) // $ access=closure.self
15+ print ( instanceField) // $ access=instanceField implicit-qualifier=closure.self
16+ }
17+ }
18+
19+ func t4( ) { // implicit-self=t4.self
20+ foo ( 123 ) { [ weak self] in // name=weak.self
21+ // Here, 'self' is an Option<C> referring to .some(<outer self>) if it
22+ // has not been GC'ed yet. Swift does not allow unqualified self access here.
23+
24+ print ( self ) // $ access=weak.self
25+
26+ // Unwrap the 'self' optional to get a strong reference.
27+ guard let self else { return } // $ access=weak.self // name=guarded.self
28+
29+ print ( self ) // $ access=guarded.self
30+ print ( instanceField) // $ access=instanceField implicit-qualifier=guarded.self
31+ }
32+ }
33+ }
You can’t perform that action at this time.
0 commit comments