Skip to content

Commit 1151104

Browse files
committed
fix getName() on module instantiations
1 parent 26df367 commit 1151104

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

ql/ql/src/codeql_ql/ast/Ast.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,7 +2226,7 @@ class ModuleExpr extends TModuleExpr, TypeRef {
22262226
or
22272227
not exists(me.getName()) and result = me.getChild().(QL::SimpleId).getValue()
22282228
or
2229-
result = me.getChild().(QL::ModuleInstantiation).getName().getChild().getValue()
2229+
result = me.getAFieldOrChild().(QL::ModuleInstantiation).getName().getChild().getValue()
22302230
}
22312231

22322232
/**
@@ -2261,7 +2261,7 @@ class ModuleExpr extends TModuleExpr, TypeRef {
22612261
* The result is either a `PredicateExpr` or a `TypeExpr`.
22622262
*/
22632263
SignatureExpr getArgument(int i) {
2264-
result.toQL() = me.getChild().(QL::ModuleInstantiation).getChild(i)
2264+
result.toQL() = me.getAFieldOrChild().(QL::ModuleInstantiation).getChild(i)
22652265
}
22662266
}
22672267

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,19 @@ module ModConsistency {
332332
* }
333333
*/
334334

335-
query predicate noName(Module mod) { not exists(mod.getName()) }
335+
query predicate noName(AstNode mod) {
336+
mod instanceof Module and
337+
not exists(mod.(Module).getName())
338+
or
339+
mod instanceof ModuleExpr and
340+
not exists(mod.(ModuleExpr).getName())
341+
}
336342

337-
query predicate nonUniqueName(Module mod) { count(mod.getName()) >= 2 }
343+
query predicate nonUniqueName(AstNode mod) {
344+
mod instanceof Module and
345+
count(mod.(Module).getName()) >= 2
346+
or
347+
mod instanceof ModuleExpr and
348+
count(mod.(ModuleExpr).getName()) >= 2
349+
}
338350
}

0 commit comments

Comments
 (0)