File tree Expand file tree Collapse file tree
unified/ql/lib/codeql/unified/internal Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11private import unified
22private import NameBinding as NameBinding
3+ private import ExprPositionsPlugin
34
45/**
5- * Holds if `expr` appears in the context of a type annotation .
6+ * Holds if `expr` appears in a context where it must refer to a type.
67 */
78predicate isInTypeContext ( Expr expr ) {
89 expr = any ( TypeCastExpr n ) .getType ( )
@@ -27,8 +28,22 @@ predicate isInTypeContext(Expr expr) {
2728 or
2829 expr = any ( AssociatedTypeDeclaration n ) .getBound ( )
2930 or
31+ expr = any ( ClassLikeDeclaration c ) .getExtensionTarget ( )
32+ or
33+ expr = any ( GenericTypeExpr gte ) .getATypeArgument ( )
34+ or
3035 expr .getParent ( ) instanceof TypeConstraint
3136 or
37+ exists ( Identifier id | id = NameBinding:: getStaticBindingTarget ( expr ) |
38+ id = any ( ClassLikeDeclaration c ) .getNameNode ( )
39+ or
40+ id = any ( TypeAliasDeclaration t ) .getNameNode ( )
41+ or
42+ id = any ( TypeParameter t ) .getNameNode ( )
43+ )
44+ or
45+ any ( ExprPositionsPlugin p ) .isInTypeContext ( expr )
46+ or
3247 isInTypeContext ( expr .getEnclosingExpr ( ) )
3348}
3449
Original file line number Diff line number Diff line change 1+ private import unified
2+ private import codeql.util.Unit
3+
4+ private module Plugins {
5+ private import ExprPositionsPluginSwift
6+ }
7+
8+ class ExprPositionsPlugin extends Unit {
9+ predicate isInTypeContext ( Expr e ) { none ( ) }
10+ }
Original file line number Diff line number Diff line change 1+ private import unified
2+ private import ExprPositionsPlugin
3+
4+ private class ExprPositionsPluginSwift extends ExprPositionsPlugin {
5+ override predicate isInTypeContext ( Expr e ) { e = any ( GenericTypeExpr g ) .getBase ( ) }
6+ }
You can’t perform that action at this time.
0 commit comments