mirror of
https://github.com/github/codeql.git
synced 2026-04-29 02:35:15 +02:00
only resolve module types if we know that the TypeExpr could possibly resolve to a module
This commit is contained in:
@@ -682,8 +682,17 @@ class TypeExpr extends TType, TypeRef {
|
||||
// resolve type
|
||||
resolveTypeExpr(this, result)
|
||||
or
|
||||
// if it resolves to a module
|
||||
exists(FileOrModule mod | resolveModuleRef(this, mod) | result = mod.toType())
|
||||
// if it resolves to a module,
|
||||
exists(FileOrModule mod | resolveModuleRef(this, mod) | result = mod.toType()) and
|
||||
result instanceof ModuleType and
|
||||
// we can get spurious results in some cases, so we restrict to where it is possible to have a module.
|
||||
(
|
||||
// only possible if this is inside a moduleInstantiation.
|
||||
this = any(ModuleExpr mod).getArgument(_).asType()
|
||||
or
|
||||
// or if it's a parameter to a parameterized module
|
||||
this = any(SignatureExpr sig, Module mod | mod.hasParameter(_, _, sig) | sig).asType()
|
||||
)
|
||||
}
|
||||
|
||||
override AstNode getAChild(string pred) {
|
||||
|
||||
11
ql/ql/test/queries/style/RedundantCast/Foo.qll
Normal file
11
ql/ql/test/queries/style/RedundantCast/Foo.qll
Normal file
@@ -0,0 +1,11 @@
|
||||
class Foo extends string {
|
||||
Foo() { this = "Foo" }
|
||||
}
|
||||
|
||||
predicate test(Foo f) { f.(Foo).toString() = "X" }
|
||||
|
||||
predicate test2(Foo a, Foo b) { a.(Foo) = b }
|
||||
|
||||
predicate called(Foo a) { a.toString() = "X" }
|
||||
|
||||
predicate test3(string s) { called(s.(Foo)) }
|
||||
@@ -0,0 +1,3 @@
|
||||
| Foo.qll:5:25:5:31 | InlineCast | Redundant cast to $@ | Foo.qll:5:28:5:30 | TypeExpr | Foo |
|
||||
| Foo.qll:7:33:7:39 | InlineCast | Redundant cast to $@ | Foo.qll:7:36:7:38 | TypeExpr | Foo |
|
||||
| Foo.qll:11:36:11:42 | InlineCast | Redundant cast to $@ | Foo.qll:11:39:11:41 | TypeExpr | Foo |
|
||||
@@ -0,0 +1 @@
|
||||
queries/style/RedundantCast.ql
|
||||
Reference in New Issue
Block a user