mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
add support for class signatures in parameterized modules
This commit is contained in:
@@ -2257,6 +2257,12 @@ class SignatureExpr extends TSignatureExpr, AstNode {
|
||||
|
||||
/** Gets the generated AST node that contains this signature expression. */
|
||||
QL::SignatureExpr toQL() { result = sig }
|
||||
|
||||
/** Gets this signature expression if it represents a predicate expression. */
|
||||
PredicateExpr asPredicate() { result = this }
|
||||
|
||||
/** Gets this signature expression if it represents a type expression. */
|
||||
TypeExpr asType() { result = this }
|
||||
}
|
||||
|
||||
/** An argument to an annotation. */
|
||||
|
||||
@@ -323,6 +323,23 @@ private predicate defines(FileOrModule m, string name, Type t, boolean public) {
|
||||
public = getPublicBool(im) and
|
||||
defines(im.getResolvedModule(), name, t, true)
|
||||
)
|
||||
or
|
||||
// classes in parameterized modules.
|
||||
exists(Module mod, SignatureExpr param, int i |
|
||||
m.asModule() = mod and
|
||||
mod.hasParameter(i, name, param) and
|
||||
public = true
|
||||
|
|
||||
// we resolve it both to the signature type
|
||||
t = param.asType().getResolvedType()
|
||||
or
|
||||
// or any instantiated type
|
||||
exists(ModuleExpr inst, SignatureExpr arg |
|
||||
inst.getArgument(i) = arg and
|
||||
inst.getResolvedModule() = m and
|
||||
t = arg.asType().getResolvedType()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
module TyConsistency {
|
||||
|
||||
@@ -11,7 +11,19 @@ module PredicateSig {
|
||||
}
|
||||
|
||||
module ClassSig {
|
||||
// TODO:
|
||||
signature class FooSig extends int;
|
||||
|
||||
module UsesFoo<FooSig FooImpl> {
|
||||
FooImpl getAnEven() { result % 2 = 0 }
|
||||
}
|
||||
|
||||
class MyFoo extends int {
|
||||
MyFoo() { this = [0 .. 10] }
|
||||
|
||||
string myFoo() { result = "myFoo" }
|
||||
}
|
||||
|
||||
string use() { result = UsesFoo<MyFoo>::getAnEven().myFoo() }
|
||||
}
|
||||
|
||||
module ModuleSig {
|
||||
|
||||
@@ -23,6 +23,8 @@ getTarget
|
||||
| Overrides.qll:29:3:29:10 | MemberCall | Overrides.qll:8:3:8:41 | ClassPredicate baz |
|
||||
| ParamModules.qll:5:28:5:41 | PredicateCall | ParamModules.qll:2:13:2:36 | ClasslessPredicate fooSig |
|
||||
| ParamModules.qll:10:26:10:49 | PredicateCall | ParamModules.qll:5:5:5:43 | ClasslessPredicate bar |
|
||||
| ParamModules.qll:26:27:26:53 | PredicateCall | ParamModules.qll:17:5:17:42 | ClasslessPredicate getAnEven |
|
||||
| ParamModules.qll:26:27:26:61 | MemberCall | ParamModules.qll:23:5:23:39 | ClassPredicate myFoo |
|
||||
| packs/other/OtherThing.qll:5:3:5:8 | PredicateCall | packs/lib/LibThing/Foo.qll:1:1:1:30 | ClasslessPredicate foo |
|
||||
| packs/other/OtherThing.qll:6:3:6:8 | PredicateCall | packs/src/SrcThing.qll:8:1:8:30 | ClasslessPredicate bar |
|
||||
| packs/src/SrcThing.qll:4:3:4:8 | PredicateCall | packs/lib/LibThing/Foo.qll:1:1:1:30 | ClasslessPredicate foo |
|
||||
|
||||
Reference in New Issue
Block a user