Skip to content

Commit dd7a64d

Browse files
authored
Merge pull request github#13141 from kaspersv/kaspersv/ql-explicit-this-receivers
QL: Enable implicit this receiver warnings
2 parents a6e8b00 + 1af1bf8 commit dd7a64d

File tree

5 files changed

+25
-20
lines changed

5 files changed

+25
-20
lines changed

ql/ql/src/codeql/Locations.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ class Location extends @location {
2525
int getEndColumn() { locations_default(this, _, _, _, _, result) }
2626

2727
/** Gets the number of lines covered by this location. */
28-
int getNumLines() { result = getEndLine() - getStartLine() + 1 }
28+
int getNumLines() { result = this.getEndLine() - this.getStartLine() + 1 }
2929

3030
/** Gets a textual representation of this element. */
3131
cached
3232
string toString() {
3333
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
34-
hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
34+
this.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
3535
result = filepath + "@" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
3636
)
3737
}

ql/ql/src/codeql_ql/style/UseSetLiteralQuery.qll

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class DisjunctionChain extends Disjunction {
1616
Formula getOperand(int i) {
1717
result =
1818
rank[i + 1](Formula operand, Location l |
19-
operand = getAnOperand*() and
19+
operand = this.getAnOperand*() and
2020
not operand instanceof Disjunction and
2121
l = operand.getLocation()
2222
|
@@ -33,16 +33,16 @@ class DisjunctionChain extends Disjunction {
3333
*/
3434
class EqualsLiteral extends ComparisonFormula {
3535
EqualsLiteral() {
36-
getOperator() = "=" and
37-
getAnOperand() instanceof Literal
36+
this.getOperator() = "=" and
37+
this.getAnOperand() instanceof Literal
3838
}
3939

4040
AstNode getOther() {
41-
result = getAnOperand() and
41+
result = this.getAnOperand() and
4242
not result instanceof Literal
4343
}
4444

45-
Literal getLiteral() { result = getAnOperand() }
45+
Literal getLiteral() { result = this.getAnOperand() }
4646
}
4747

4848
/**
@@ -60,29 +60,33 @@ class DisjunctionEqualsLiteral extends DisjunctionChain {
6060
DisjunctionEqualsLiteral() {
6161
// VarAccess on the same variable
6262
exists(VarDef v |
63-
forex(Formula f | f = getOperand(_) |
63+
forex(Formula f | f = this.getOperand(_) |
6464
f.(EqualsLiteral).getAnOperand().(VarAccess).getDeclaration() = v
6565
) and
66-
firstOperand = getOperand(0).(EqualsLiteral).getAnOperand() and
66+
firstOperand = this.getOperand(0).(EqualsLiteral).getAnOperand() and
6767
firstOperand.(VarAccess).getDeclaration() = v
6868
)
6969
or
7070
// FieldAccess on the same variable
7171
exists(FieldDecl v |
72-
forex(Formula f | f = getOperand(_) |
72+
forex(Formula f | f = this.getOperand(_) |
7373
f.(EqualsLiteral).getAnOperand().(FieldAccess).getDeclaration() = v
7474
) and
75-
firstOperand = getOperand(0).(EqualsLiteral).getAnOperand() and
75+
firstOperand = this.getOperand(0).(EqualsLiteral).getAnOperand() and
7676
firstOperand.(FieldAccess).getDeclaration() = v
7777
)
7878
or
7979
// ThisAccess
80-
forex(Formula f | f = getOperand(_) | f.(EqualsLiteral).getAnOperand() instanceof ThisAccess) and
81-
firstOperand = getOperand(0).(EqualsLiteral).getAnOperand().(ThisAccess)
80+
forex(Formula f | f = this.getOperand(_) |
81+
f.(EqualsLiteral).getAnOperand() instanceof ThisAccess
82+
) and
83+
firstOperand = this.getOperand(0).(EqualsLiteral).getAnOperand().(ThisAccess)
8284
or
8385
// ResultAccess
84-
forex(Formula f | f = getOperand(_) | f.(EqualsLiteral).getAnOperand() instanceof ResultAccess) and
85-
firstOperand = getOperand(0).(EqualsLiteral).getAnOperand().(ResultAccess)
86+
forex(Formula f | f = this.getOperand(_) |
87+
f.(EqualsLiteral).getAnOperand() instanceof ResultAccess
88+
) and
89+
firstOperand = this.getOperand(0).(EqualsLiteral).getAnOperand().(ResultAccess)
8690
// (in principle something like GlobalValueNumbering could be used to generalize this)
8791
}
8892

@@ -100,8 +104,8 @@ class DisjunctionEqualsLiteral extends DisjunctionChain {
100104
*/
101105
class CallLiteral extends Call {
102106
CallLiteral() {
103-
getNumberOfArguments() = 1 and
104-
getArgument(0) instanceof Literal
107+
this.getNumberOfArguments() = 1 and
108+
this.getArgument(0) instanceof Literal
105109
}
106110
}
107111

@@ -118,7 +122,7 @@ class DisjunctionPredicateLiteral extends DisjunctionChain {
118122
DisjunctionPredicateLiteral() {
119123
// Call to the same target
120124
exists(PredicateOrBuiltin target |
121-
forex(Formula f | f = getOperand(_) | f.(CallLiteral).getTarget() = target)
125+
forex(Formula f | f = this.getOperand(_) | f.(CallLiteral).getTarget() = target)
122126
)
123127
}
124128
}

ql/ql/src/qlpack.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ extractor: ql
88
dependencies:
99
codeql/typos: ${workspace}
1010
codeql/util: ${workspace}
11+
warnOnImplicitThis: true

ql/ql/test/callgraph/Foo.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ query predicate test() { foo() }
77
class Foo extends AstNode {
88
predicate bar() { none() }
99

10-
predicate baz() { bar() }
10+
predicate baz() { this.bar() }
1111
}
1212

1313
class Sub extends Foo {

ql/ql/test/callgraph/callgraph.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ getTarget
55
| Bar.qll:30:12:30:32 | MemberCall | Bar.qll:19:7:19:18 | ClassPredicate getParameter |
66
| Baz.qll:8:18:8:44 | MemberCall | Baz.qll:4:10:4:24 | ClassPredicate getImportedPath |
77
| Foo.qll:5:26:5:30 | PredicateCall | Foo.qll:3:11:3:13 | ClasslessPredicate foo |
8-
| Foo.qll:10:21:10:25 | PredicateCall | Foo.qll:8:13:8:15 | ClassPredicate bar |
8+
| Foo.qll:10:21:10:30 | MemberCall | Foo.qll:8:13:8:15 | ClassPredicate bar |
99
| Foo.qll:14:34:14:44 | MemberCall | Foo.qll:10:13:10:15 | ClassPredicate baz |
1010
| Foo.qll:17:27:17:42 | MemberCall | Foo.qll:8:13:8:15 | ClassPredicate bar |
1111
| Foo.qll:29:5:29:16 | PredicateCall | Foo.qll:20:13:20:20 | ClasslessPredicate myThing2 |

0 commit comments

Comments
 (0)