11private import unified
22private import codeql.util.Unit
3+ private import codeql.unified.internal.LocalNameBinding
34private import codeql.unified.internal.NameBindingPluginSwift // ensure overrides are seen
45
56/** Extension point for language-specific inputs to name binding. */
@@ -14,13 +15,16 @@ class NameBindingPlugin extends Unit {
1415 predicate isInstanceMember ( ClassLikeDeclaration cls , Member member ) { none ( ) }
1516
1617 /**
17- * Holds if `member` is only visible in its local scope, and can thus be entirely resolved
18+ * Holds if `binding`, declared by ` member` is only visible in its local scope, and can thus be entirely resolved
1819 * by local name-binding, suppressing any store-steps that would otherwise be induced from the member.
1920 *
2021 * Need only be implemented for members that occur in the context of class or top-level, as other
2122 * contexts are considered local already.
23+ *
24+ * `binding` refers to an `Identifier` or `BulkImportingPattern` bound by the member.
2225 */
23- predicate isPrivateToLocalScope ( Stmt member ) { none ( ) }
26+ bindingset [ member, binding]
27+ predicate isPrivateToLocalScope ( Stmt member , AstNode binding ) { none ( ) }
2428}
2529
2630/** Holds if `member` is an instance member. */
@@ -31,9 +35,18 @@ predicate isInstanceMember(Member member) {
3135 )
3236}
3337
34- /** Holds if `member` is only visible in its local scope. */
35- predicate isPrivateToLocalScope ( Stmt member ) {
36- any ( NameBindingPlugin p ) .isPrivateToLocalScope ( member )
38+ /** Holds if `binding` is only visible in its local scope. */
39+ pragma [ nomagic]
40+ predicate isPrivateToLocalScope ( AstNode binding ) {
41+ exists ( Stmt member |
42+ bindingContext ( binding , _, member ) and
43+ (
44+ member = any ( ClassLikeDeclaration cls ) .getAMember ( ) or
45+ member = any ( TopLevel t ) .getBody ( ) .getAStmt ( )
46+ ) and
47+ ( binding instanceof NameDeclaration or binding instanceof BulkImportingPattern ) and
48+ any ( NameBindingPlugin p ) .isPrivateToLocalScope ( member , binding )
49+ )
3750}
3851
3952/**
0 commit comments