File tree Expand file tree Collapse file tree 3 files changed +30
-4
lines changed
test/queries/style/OmittableExists Expand file tree Collapse file tree 3 files changed +30
-4
lines changed Original file line number Diff line number Diff line change 1010
1111import ql
1212
13+ class AggregateOrForQuantifier extends AstNode {
14+ AggregateOrForQuantifier ( ) {
15+ this instanceof FullAggregate or this instanceof Forex or this instanceof Forall
16+ }
17+ }
18+
1319from VarDecl existsArgument , VarAccess use
1420where
1521 existsArgument = any ( Exists e ) .getAnArgument ( ) and
1622 use = unique( | | existsArgument .getAnAccess ( ) ) and
17- exists ( Call c , int argPos | c .getArgument ( argPos ) = use |
18- existsArgument .getType ( ) = c .getTarget ( ) .getParameterType ( argPos ) .getASuperType * ( )
19- )
23+ exists ( Call c , int argPos , Type paramType |
24+ c .getArgument ( argPos ) = use and paramType = c .getTarget ( ) .getParameterType ( argPos )
25+ |
26+ existsArgument .getType ( ) = paramType .getASuperType * ( ) and
27+ not paramType instanceof DatabaseType
28+ ) and
29+ not use .getParent * ( ) instanceof AggregateOrForQuantifier
2030select existsArgument , "This exists variable can be omitted by using a don't-care expression $@." ,
2131 use , "in this argument"
Original file line number Diff line number Diff line change 1- | Test.qll:10 :10:10 :14 | i | This exists variable can be omitted by using a don't-care expression $@. | Test.qll:10 :29:10 :29 | i | in this argument |
1+ | Test.qll:18 :10:18 :14 | i | This exists variable can be omitted by using a don't-care expression $@. | Test.qll:18 :29:18 :29 | i | in this argument |
Original file line number Diff line number Diff line change @@ -2,10 +2,18 @@ predicate aPredicate(int i) { none() }
22
33predicate anotherPredicate ( int i ) { none ( ) }
44
5+ predicate yetAnotherPredicate ( int i , int y ) { none ( ) }
6+
7+ predicate dbTypePredicate ( @location l ) { none ( ) }
8+
59class SmallInt extends int {
610 SmallInt ( ) { this = [ 0 .. 10 ] }
711}
812
13+ class Location extends @location {
14+ string toString ( ) { result = "" }
15+ }
16+
917predicate test ( ) {
1018 exists ( int i | aPredicate ( i ) ) // BAD
1119 or
@@ -15,5 +23,13 @@ predicate test() {
1523 or
1624 exists ( int i | aPredicate ( i ) and exists ( int i2 | i = i2 ) ) // GOOD
1725 or
26+ exists ( int i | count ( int y | yetAnotherPredicate ( i , y ) ) > 0 ) // GOOD
27+ or
28+ exists ( int i | forex ( int y | yetAnotherPredicate ( i , y ) ) ) // GOOD
29+ or
30+ exists ( int i | forall ( int y | yetAnotherPredicate ( i , y ) ) ) // GOOD
31+ or
1832 exists ( SmallInt i | aPredicate ( i ) ) // GOOD
33+ or
34+ exists ( Location l | dbTypePredicate ( l ) ) // GOOD
1935}
You can’t perform that action at this time.
0 commit comments