Skip to content

Commit d30b7a0

Browse files
committed
unified: Simplify uncertain scopes
Marking Members as uncertain scopes led to inaccurate resolution when a member referred to itself, because the uncertain scope (Member) appeared in the scope chain before the LocalName scope (ClassLikeDeclaration). Meanwhile, one of the arguments for doing it, avoiding base classes etc from hitting the uncertain scope, was already fixed by local scope tree-rewrites. It gets harder to detect if a given access appears in static or instance context, but perhaps we'll probably want to expose such information through a separate predicate anyway.
1 parent e88dde7 commit d30b7a0

2 files changed

Lines changed: 2 additions & 13 deletions

File tree

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,7 @@ private module LocalNameBindingInput implements LocalNameBindingInputSig<Locatio
317317

318318
predicate uncertainScope(AstNode scope) {
319319
// Classes can have uncertain members due to unqualified access to inherited members.
320-
// Instead of marking the whole class scope as uncertain, we mark its individual members, for two reasons:
321-
// - Base types and type parameter constraints will then not resolve through the uncertain scope.
322-
// - It becomes easy to determine if a given uncertain lookup appears in instance context or static context
323-
// because the associated uncertain scope is a Member, from which we can check static-ness.
324-
scope = any(ClassLikeDeclaration cls).getAMember()
320+
scope = any(ClassLikeDeclaration cls)
325321
or
326322
scope = any(TopLevel t).getBody() // Imported names are in scope here
327323
or

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,7 @@ NameBindingNode getModuleNodeFromFile(File f) {
118118
}
119119

120120
/** Gets the name-binding node associated with the given uncertain scope node. */
121-
private NameBindingNode getNodeFromUncertainScope(AstNode n) {
122-
exists(ClassLikeDeclaration cls |
123-
n = cls.getAMember() and // note: must align with LocalNameBindingInput::uncertainScope
124-
result.isLocalNamespace(cls)
125-
)
126-
or
127-
result.isLocalNamespace(n)
128-
}
121+
private NameBindingNode getNodeFromUncertainScope(AstNode n) { result.isLocalNamespace(n) }
129122

130123
predicate readStep(NameBindingNode node1, string name, NameBindingNode node2) {
131124
exists(MemberAccessExpr expr |

0 commit comments

Comments
 (0)