Skip to content

Commit 9d9663d

Browse files
committed
and consistency query that will highlight new consistency errors
1 parent 74b1c19 commit 9d9663d

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

ql/src/codeql_ql/ast/internal/Variable.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import ql
2-
import codeql_ql.ast.internal.AstNodes
2+
private import codeql_ql.ast.internal.AstNodes
33

44
private class TScope =
55
TClass or TAggregate or TQuantifier or TSelect or TPredicate or TNewTypeBranch;
@@ -89,4 +89,8 @@ module VarConsistency {
8989
decl = f.getDeclaration() and
9090
strictcount(f.getDeclaration()) > 1
9191
}
92+
93+
query predicate noFieldDef(FieldAccess f) { not exists(f.getDeclaration()) }
94+
95+
query predicate noVarDef(VarAccess v) { not exists(v.getDeclaration()) }
9296
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* @name Consistency predicate that should be empty
3+
* @description This query should have no results on the CodeQL repos.
4+
* It's marked as a warning query to make the results visible.
5+
* @kind problem
6+
* @problem.severity warning
7+
* @precision very-high
8+
* @id ql/diagnostics/empty-consitencies
9+
*/
10+
11+
import ql
12+
import codeql_ql.ast.internal.Predicate::PredConsistency as PredConsistency
13+
import codeql_ql.ast.internal.Type::TyConsistency as TypeConsistency
14+
import codeql_ql.ast.internal.Builtins::BuildinsConsistency as BuildinsConsistency
15+
import codeql_ql.ast.internal.Module::ModConsistency as ModConsistency
16+
import codeql_ql.ast.internal.Variable::VarConsistency as VarConsistency
17+
18+
from AstNode node, string msg
19+
where
20+
PredConsistency::noResolveCall(node) and msg = "PredConsistency::noResolveCall"
21+
or
22+
TypeConsistency::noResolve(node) and msg = "TypeConsistency::noResolve"
23+
or
24+
TypeConsistency::exprNoType(node) and msg = "TypeConsistency::exprNoType"
25+
or
26+
TypeConsistency::varDefNoType(node) and msg = "TypeConsistency::varDefNoType"
27+
or
28+
//or // has 1 result, but the CodeQL compiler also can't figure out that one. I suppoed the file is never imported.
29+
//TypeConsistency::noResolve(node) and msg = "TypeConsistency::noResolve"
30+
//or // has 1 result, but the CodeQL compiler also can't figure out that one. Same file as above.
31+
//ModConsistency::noResolve(node) and msg = "ModConsistency::noResolve"
32+
ModConsistency::noResolveModuleExpr(node) and msg = "ModConsistency::noResolveModuleExpr"
33+
or
34+
VarConsistency::noFieldDef(node) and msg = "VarConsistency::noFieldDef"
35+
or
36+
VarConsistency::noVarDef(node) and msg = "VarConsistency::noVarDef"
37+
select node, msg

0 commit comments

Comments
 (0)