File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
test/queries/style/DeadCode Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,18 @@ private AstNode alive() {
7777 or
7878 // recursive cases
7979 result = aliveStep ( alive ( ) )
80+ or
81+ // cached predicates inside a cached module, because they can group cached predicate.
82+ // this is deliberately not part of `aliveStep`, as it only means the predicate is live, but not if it's queryable.
83+ exists ( Module mod , ClasslessPredicate pred | pred = alive ( ) |
84+ not pred .isPrivate ( ) and
85+ not result .( ClasslessPredicate ) .isPrivate ( ) and
86+ pred .hasAnnotation ( "cached" ) and
87+ result .hasAnnotation ( "cached" ) and
88+ pred .getParent ( ) = mod and
89+ result .getParent ( ) = mod and
90+ mod .hasAnnotation ( "cached" )
91+ )
8092}
8193
8294private AstNode aliveStep ( AstNode prev ) {
@@ -172,6 +184,8 @@ private AstNode aliveStep(AstNode prev) {
172184 or
173185 // the implements of a module
174186 result = prev .( Module ) .getImplements ( _)
187+ or
188+ result = prev .( PredicateExpr ) .getQualifier ( )
175189}
176190
177191private AstNode deprecated ( ) {
Original file line number Diff line number Diff line change @@ -7,3 +7,26 @@ private module Mixed {
77}
88
99predicate usesAlive ( ) { Mixed:: alive1 ( ) }
10+
11+ cached
12+ private module Cached {
13+ cached
14+ predicate isUsed ( ) { any ( ) }
15+
16+ cached
17+ predicate isNotUsed ( ) { any ( ) }
18+ }
19+
20+ module UseCache {
21+ private import Cached
22+
23+ predicate usesCached ( ) { isUsed ( ) }
24+ }
25+
26+ private module Foo {
27+ signature predicate bar ( ) ;
28+ }
29+
30+ module ValidationMethod< Foo:: bar / 0 sig> {
31+ predicate impl ( ) { sig ( ) }
32+ }
You can’t perform that action at this time.
0 commit comments