support more types on aggregates

This commit is contained in:
Erik Krogh Kristensen
2021-05-29 17:31:53 +00:00
committed by GitHub
parent c8d0384907
commit 8dc3948221
3 changed files with 30 additions and 5 deletions

View File

@@ -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) {

View File

@@ -13,3 +13,5 @@ class Foo extends AstNode {
class Sub extends Foo {
override predicate baz() { super.baz() }
}
query predicate test2() { any(Foo f).bar() }

View File

@@ -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 |