Skip to content

Commit 7d62b9e

Browse files
committed
move the pruning for module resolution of TypeExprs
1 parent 6d3808b commit 7d62b9e

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -683,16 +683,7 @@ class TypeExpr extends TType, TypeRef {
683683
resolveTypeExpr(this, result)
684684
or
685685
// if it resolves to a module,
686-
exists(FileOrModule mod | resolveModuleRef(this, mod) | result = mod.toType()) and
687-
result instanceof ModuleType and
688-
// we can get spurious results in some cases, so we restrict to where it is possible to have a module.
689-
(
690-
// only possible if this is inside a moduleInstantiation.
691-
this = any(ModuleExpr mod).getArgument(_).asType()
692-
or
693-
// or if it's a parameter to a parameterized module
694-
this = any(SignatureExpr sig, Module mod | mod.hasParameter(_, _, sig) | sig).asType()
695-
)
686+
exists(FileOrModule mod | resolveModuleRef(this, mod) | result = mod.toType())
696687
}
697688

698689
override AstNode getAChild(string pred) {

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,20 @@ private module Cached {
218218
not exists(me.(ModuleExpr).getQualifier()) and
219219
exists(ContainerOrModule enclosing, string name | resolveModuleRefHelper(me, enclosing, name) |
220220
definesModule(enclosing, name, m, _)
221+
) and
222+
(
223+
not me instanceof TypeExpr
224+
or
225+
// remove some spurious results that can happen with `TypeExpr`
226+
me instanceof TypeExpr and
227+
m instanceof Module_ and // TypeExpr can only resolve to a Module, and only in some scenarios
228+
(
229+
// only possible if this is inside a moduleInstantiation.
230+
me = any(ModuleExpr mod).getArgument(_).asType()
231+
or
232+
// or if it's a parameter to a parameterized module
233+
me = any(SignatureExpr sig, Module mod | mod.hasParameter(_, _, sig) | sig).asType()
234+
)
221235
)
222236
or
223237
exists(FileOrModule mid |

0 commit comments

Comments
 (0)