Skip to content

Commit 50f934b

Browse files
committed
unified: Don't track trivial name aliasse
1 parent a3f21a5 commit 50f934b

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,26 @@ private module TrackNamespaceInput implements TrackInputSig {
280280

281281
private module TrackNamespace = Track<TrackNamespaceInput>;
282282

283+
/**
284+
* Holds if `decl` is a trivial local alias for an imported name.
285+
*
286+
* Declaration-tracking usually stops at type-aliases, but trivial aliases
287+
* will be passed through.
288+
*/
289+
predicate isTrivialNameAlias(NameDeclaration decl) {
290+
exists(ImportDeclaration imprt |
291+
decl = getIdentifierFromRef(imprt.getPattern()) and
292+
decl.getName() = getIdentifierFromRef(imprt.getImportedExpr()).getValue()
293+
)
294+
}
295+
283296
private module TrackNameDeclarationInput implements TrackInputSig {
284-
predicate shouldTrack(NameBindingNode node) { node.isIdentifier(any(NameDeclaration d)) }
297+
predicate shouldTrack(NameBindingNode node) {
298+
exists(NameDeclaration decl |
299+
node.isIdentifier(decl) and
300+
not isTrivialNameAlias(decl)
301+
)
302+
}
285303
}
286304

287305
private module TrackNameDeclaration = Track<TrackNameDeclarationInput>;
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
class A {} // name=Target1.A
22

3-
private import class Target2.B // $ access=Target2.B // name=LocalB
3+
private import class Target2.B // $ access=Target2.B
44

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
5+
private let x: B.C; // $ access=Target2.B access=Target2.B.C

0 commit comments

Comments
 (0)