Skip to content

Commit a3f21a5

Browse files
committed
unified: Support scoped imports
Scoped imports like 'import class B.C' are mapped to an AST of form ImportDeclartion pattern: NamePattern "C" importedExpr: MemberAccessExpr base: "B" member: "C" The NamePattern introduces a local alias for 'C', but unlike type aliases we also resolve to the ultimate target, when it's coming through an import.
1 parent 0cf2871 commit a3f21a5

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

unified/ql/lib/codeql/unified/internal/StaticNameBinding.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ predicate valueStep(NameBindingNode node1, NameBindingNode node2) {
181181
node1 = getModuleNodeFromFile(top.getFile()) and
182182
node2.isLocalNamespace(top.getBody()) // implicitly import own module
183183
)
184+
or
185+
exists(ImportDeclaration imprt |
186+
node1 = getNodeFromRef(imprt.getImportedExpr()) and
187+
node2 = getNodeFromRef(imprt.getPattern())
188+
)
184189
}
185190

186191
predicate inheritanceStep(NameBindingNode supertype, NameBindingNode subtype) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
class A {} // name=Target1.A
2+
3+
private import class Target2.B // $ access=Target2.B // name=LocalB
4+
5+
// Note: currently the local name 'B' introduced by the scoped import is also resolved as a target
6+
private let x: B.C; // $ access=Target2.B access=Target2.B.C access=LocalB
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
class A {} // name=Target2.A
2+
3+
class B { // name=Target2.B
4+
class C {} // name=Target2.B.C
5+
}

0 commit comments

Comments
 (0)