Skip to content

Commit 5dbeaa1

Browse files
authored
QL: Merge pull request #123 from github/tausbn/add-instanceof-super-resolution
Support `super` with `instanceof`
2 parents 370d75b + 1375e1d commit 5dbeaa1

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

ql/src/codeql_ql/ast/Ast.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,11 @@ class Class extends TClass, TypeDeclaration, ModuleDeclaration {
754754
*/
755755
TypeExpr getASuperType() { toQL(result) = cls.getExtends(_) }
756756

757+
/**
758+
* Gets a type referenced in the `instanceof` part of the class declaration.
759+
*/
760+
TypeExpr getAnInstanceofType() { toQL(result) = cls.getInstanceof(_) }
761+
757762
/** Gets the type that this class is defined to be an alias of. */
758763
TypeExpr getAliasType() { toQL(result) = cls.getChild(_).(QL::TypeAliasBody).getChild() }
759764

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ private module Cached {
7979
)
8080
or
8181
// super calls
82-
exists(Super sup, ClassType type |
82+
exists(Super sup, ClassType type, Type supertype |
8383
mc.getBase() = sup and
8484
sup.getEnclosingPredicate().(ClassPredicate).getParent().getType() = type and
85-
p = type.getASuperType().getClassPredicate(mc.getMemberName(), mc.getNumberOfArguments())
85+
supertype in [type.getASuperType(), type.getAnInstanceofType()] and
86+
p = supertype.getClassPredicate(mc.getMemberName(), mc.getNumberOfArguments())
8687
)
8788
}
8889

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class ClassType extends Type, TClass {
9494

9595
override Type getASuperType() { result = decl.getASuperType().getResolvedType() }
9696

97+
Type getAnInstanceofType() { result = decl.getAnInstanceofType().getResolvedType() }
98+
9799
override Type getAnInternalSuperType() {
98100
result.(ClassCharType).getClassType() = this
99101
or

0 commit comments

Comments
 (0)