diff --git a/ql/src/codeql_ql/ast/Ast.qll b/ql/src/codeql_ql/ast/Ast.qll index 70d0d8307a2..d682d05f0ee 100644 --- a/ql/src/codeql_ql/ast/Ast.qll +++ b/ql/src/codeql_ql/ast/Ast.qll @@ -1339,6 +1339,19 @@ class ExprAggregate extends TExprAggregate, Expr { pred = indexedMember("getOrderBy", i) and result = this.getOrderBy(i) ) } + + override Type getType() { + exists(PrimitiveType prim | prim = result | + kind.regexpMatch("(strict)?count|sum|min|max|rank") and + result.getName() = "int" + or + kind.regexpMatch("(strict)?concat") and + result.getName() = "string" + ) + or + not kind = ["count", "strictcount"] and + result = getExpr(0).getType() + } } /** An aggregate expression, such as `count` or `sum`. */ @@ -1389,12 +1402,21 @@ class Aggregate extends TAggregate, Expr { override string getAPrimaryQlClass() { result = "Aggregate[" + kind + "]" } - override PrimitiveType getType() { - kind.regexpMatch("(strict)?count|sum|min|max|rank") and - result.getName() = "int" + override Type getType() { + exists(PrimitiveType prim | prim = result | + kind.regexpMatch("(strict)?count|sum|min|max|rank") and + result.getName() = "int" + or + kind.regexpMatch("(strict)?concat") and + result.getName() = "string" + ) or - kind.regexpMatch("(strict)?concat") and - result.getName() = "string" + kind = ["any", "min", "max"] and + not exists(getExpr(_)) and + result = getArgument(0).getTypeExpr().getResolvedType() + or + not kind = ["count", "strictcount"] and + result = getExpr(0).getType() } override AstNode getAChild(string pred) { diff --git a/ql/test/callgraph/Foo.qll b/ql/test/callgraph/Foo.qll index b289193b5e8..e76d6c18bb2 100644 --- a/ql/test/callgraph/Foo.qll +++ b/ql/test/callgraph/Foo.qll @@ -13,3 +13,5 @@ class Foo extends AstNode { class Sub extends Foo { override predicate baz() { super.baz() } } + +query predicate test2() { any(Foo f).bar() } diff --git a/ql/test/callgraph/callgraph.expected b/ql/test/callgraph/callgraph.expected index 497b6e6591e..b3fc75af731 100644 --- a/ql/test/callgraph/callgraph.expected +++ b/ql/test/callgraph/callgraph.expected @@ -1,3 +1,4 @@ | Foo.qll:5:26:5:30 | PredicateCall | Foo.qll:3:1:3:26 | foo | | Foo.qll:10:21:10:25 | PredicateCall | Foo.qll:8:3:8:28 | ClassPredicate | | Foo.qll:14:30:14:40 | MemberCall | Foo.qll:10:3:10:27 | ClassPredicate | +| Foo.qll:17:27:17:42 | MemberCall | Foo.qll:8:3:8:28 | ClassPredicate |