Skip to content

Commit 8dc3948

Browse files
authored
support more types on aggregates
1 parent c8d0384 commit 8dc3948

3 files changed

Lines changed: 30 additions & 5 deletions

File tree

ql/src/codeql_ql/ast/Ast.qll

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,19 @@ class ExprAggregate extends TExprAggregate, Expr {
13391339
pred = indexedMember("getOrderBy", i) and result = this.getOrderBy(i)
13401340
)
13411341
}
1342+
1343+
override Type getType() {
1344+
exists(PrimitiveType prim | prim = result |
1345+
kind.regexpMatch("(strict)?count|sum|min|max|rank") and
1346+
result.getName() = "int"
1347+
or
1348+
kind.regexpMatch("(strict)?concat") and
1349+
result.getName() = "string"
1350+
)
1351+
or
1352+
not kind = ["count", "strictcount"] and
1353+
result = getExpr(0).getType()
1354+
}
13421355
}
13431356

13441357
/** An aggregate expression, such as `count` or `sum`. */
@@ -1389,12 +1402,21 @@ class Aggregate extends TAggregate, Expr {
13891402

13901403
override string getAPrimaryQlClass() { result = "Aggregate[" + kind + "]" }
13911404

1392-
override PrimitiveType getType() {
1393-
kind.regexpMatch("(strict)?count|sum|min|max|rank") and
1394-
result.getName() = "int"
1405+
override Type getType() {
1406+
exists(PrimitiveType prim | prim = result |
1407+
kind.regexpMatch("(strict)?count|sum|min|max|rank") and
1408+
result.getName() = "int"
1409+
or
1410+
kind.regexpMatch("(strict)?concat") and
1411+
result.getName() = "string"
1412+
)
1413+
or
1414+
kind = ["any", "min", "max"] and
1415+
not exists(getExpr(_)) and
1416+
result = getArgument(0).getTypeExpr().getResolvedType()
13951417
or
1396-
kind.regexpMatch("(strict)?concat") and
1397-
result.getName() = "string"
1418+
not kind = ["count", "strictcount"] and
1419+
result = getExpr(0).getType()
13981420
}
13991421

14001422
override AstNode getAChild(string pred) {

ql/test/callgraph/Foo.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ class Foo extends AstNode {
1313
class Sub extends Foo {
1414
override predicate baz() { super.baz() }
1515
}
16+
17+
query predicate test2() { any(Foo f).bar() }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
| Foo.qll:5:26:5:30 | PredicateCall | Foo.qll:3:1:3:26 | foo |
22
| Foo.qll:10:21:10:25 | PredicateCall | Foo.qll:8:3:8:28 | ClassPredicate |
33
| Foo.qll:14:30:14:40 | MemberCall | Foo.qll:10:3:10:27 | ClassPredicate |
4+
| Foo.qll:17:27:17:42 | MemberCall | Foo.qll:8:3:8:28 | ClassPredicate |

0 commit comments

Comments
 (0)