Skip to content

Commit 88ee20f

Browse files
authored
Merge pull request #20331 from michaelnebel/ql/ql4ql
Ql: Fix some Ql4Ql violations.
2 parents 2a932f0 + 367027e commit 88ee20f

File tree

8 files changed

+25
-17
lines changed

8 files changed

+25
-17
lines changed

ql/ql/src/codeql_ql/style/RedundantCastQuery.qll

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import ql
22

33
class RedundantInlineCast extends AstNode instanceof InlineCast {
4-
Type t;
5-
64
RedundantInlineCast() {
7-
t = unique( | | super.getType()) and
8-
(
5+
exists(Type t |
6+
t = unique( | | super.getType()) and
7+
// noopt can require explicit casts
8+
not this.getEnclosingPredicate().getAnAnnotation() instanceof NoOpt
9+
|
910
// The cast is to the type the base expression already has
1011
t = unique( | | super.getBase().getType())
1112
or
@@ -23,9 +24,7 @@ class RedundantInlineCast extends AstNode instanceof InlineCast {
2324
target = unique( | | call.getTarget()) and
2425
t = unique( | | target.getParameterType(i))
2526
)
26-
) and
27-
// noopt can require explicit casts
28-
not this.getEnclosingPredicate().getAnAnnotation() instanceof NoOpt
27+
)
2928
}
3029

3130
TypeExpr getTypeExpr() { result = super.getTypeExpr() }
@@ -49,15 +48,16 @@ private class AnyCast extends AstNode instanceof FullAggregate {
4948
// `foo = any(Bar b)` is effectively a cast to `Bar`.
5049
class RedundantAnyCast extends AstNode instanceof ComparisonFormula {
5150
AnyCast cast;
52-
Expr operand;
5351

5452
RedundantAnyCast() {
5553
super.getOperator() = "=" and
5654
super.getAnOperand() = cast and
57-
super.getAnOperand() = operand and
58-
cast != operand and
59-
unique( | | operand.getType()).getASuperType*() =
60-
unique( | | cast.getTypeExpr().getResolvedType()) and
55+
exists(Expr operand |
56+
super.getAnOperand() = operand and
57+
cast != operand and
58+
unique( | | operand.getType()).getASuperType*() =
59+
unique( | | cast.getTypeExpr().getResolvedType())
60+
) and
6161
not this.getEnclosingPredicate().getAnAnnotation() instanceof NoOpt
6262
}
6363

ql/ql/test/queries/performance/VarUnusedInDisjunct/Test.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,6 @@ class HasField extends Big {
165165
or
166166
this.toString().matches("%foo") // <- field only defined here.
167167
}
168+
169+
Big getField() { result = field }
168170
}

ql/ql/test/queries/style/Misspelling/Misspelling.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
| Test.qll:4:7:4:26 | Class PublicallyAccessible | This class name contains the common misspelling 'publically', which should instead be 'publicly'. |
33
| Test.qll:5:3:5:20 | FieldDecl | This field name contains the common misspelling 'occurences', which should instead be 'occurrences'. |
44
| Test.qll:10:13:10:23 | ClassPredicate hasAgrument | This predicate name contains the common misspelling 'agrument', which should instead be 'argument'. |
5-
| Test.qll:13:1:16:3 | QLDoc | This comment contains the non-US spelling 'colour', which should instead be 'color'. |
6-
| Test.qll:17:7:17:17 | Class AnalysedInt | This class name contains the non-US spelling 'analysed', which should instead be 'analyzed'. |
5+
| Test.qll:15:1:18:3 | QLDoc | This comment contains the non-US spelling 'colour', which should instead be 'color'. |
6+
| Test.qll:19:7:19:17 | Class AnalysedInt | This class name contains the non-US spelling 'analysed', which should instead be 'analyzed'. |

ql/ql/test/queries/style/Misspelling/Test.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class PublicallyAccessible extends string {
88

99
// should be argument
1010
predicate hasAgrument() { none() }
11+
12+
int getNum() { result = numOccurences }
1113
}
1214

1315
/**

ql/ql/test/queries/style/UseInstanceofExtension/Foo.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class Inst3 extends string {
2222
Range range;
2323

2424
Inst3() { this = range }
25+
26+
Range getRange() { result = range }
2527
}
2628

2729
class Inst4 extends string {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
| Foo.qll:7:7:7:10 | Class Inst | Consider defining this class as non-extending subtype of $@. | Foo.qll:1:7:1:11 | Class Range | Range |
22
| Foo.qll:15:7:15:11 | Class Inst2 | Consider defining this class as non-extending subtype of $@. | Foo.qll:1:7:1:11 | Class Range | Range |
33
| Foo.qll:21:7:21:11 | Class Inst3 | Consider defining this class as non-extending subtype of $@. | Foo.qll:1:7:1:11 | Class Range | Range |
4-
| Foo.qll:27:7:27:11 | Class Inst4 | Consider defining this class as non-extending subtype of $@. | Foo.qll:1:7:1:11 | Class Range | Range |
4+
| Foo.qll:29:7:29:11 | Class Inst4 | Consider defining this class as non-extending subtype of $@. | Foo.qll:1:7:1:11 | Class Range | Range |

ql/ql/test/queries/style/UseSetLiteral/UseSetLiteral.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
| test.qll:62:7:65:14 | Disjunction | This formula of 4 comparisons can be replaced with a single equality on a set literal, improving readability. |
55
| test.qll:68:7:71:13 | Disjunction | This formula of 4 comparisons can be replaced with a single equality on a set literal, improving readability. |
66
| test.qll:74:7:77:13 | Disjunction | This formula of 4 comparisons can be replaced with a single equality on a set literal, improving readability. |
7-
| test.qll:87:3:90:9 | Disjunction | This formula of 4 predicate calls can be replaced with a single call on a set literal, improving readability. |
8-
| test.qll:128:3:134:3 | Disjunction | This formula of 4 comparisons can be replaced with a single equality on a set literal, improving readability. |
7+
| test.qll:89:3:92:9 | Disjunction | This formula of 4 predicate calls can be replaced with a single call on a set literal, improving readability. |
8+
| test.qll:130:3:136:3 | Disjunction | This formula of 4 comparisons can be replaced with a single equality on a set literal, improving readability. |

ql/ql/test/queries/style/UseSetLiteral/test.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class MyTest8Class extends int {
8181
predicate is(int x) { x = this }
8282

8383
int get() { result = this }
84+
85+
string getS() { result = s }
8486
}
8587

8688
predicate test9(MyTest8Class c) {

0 commit comments

Comments
 (0)