Skip to content

Commit 4db27cf

Browse files
committed
temp
1 parent 8316dc5 commit 4db27cf

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

shared/namebinding/codeql/namebinding/LocalNameBinding.qll

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,14 @@ module LocalNameBinding<LocationSig Location, LocalNameBindingInputSig<Location>
126126
}
127127

128128
pragma[nomagic]
129-
private AstNode getConditionChild(Conditional cond, AstNode parent, int index) {
130-
parent = cond.getCondition() and
131-
result = getChild(parent, index)
129+
private predicate conditionHasChildAt(Conditional conditional, AstNode condition, int index) {
130+
condition = conditional.getCondition() and
131+
(
132+
exists(getChild(condition, index))
133+
or
134+
// safeguard against empty conditions
135+
not exists(getChild(condition, _)) and index = 0
136+
)
132137
}
133138

134139
/**
@@ -150,21 +155,16 @@ module LocalNameBinding<LocationSig Location, LocalNameBindingInputSig<Location>
150155
*/
151156
private AstNode getChildAdj(AstNode parent, int index) {
152157
result = getChild(parent, index) and
153-
not parent instanceof Conditional and
154-
not parent = any(Conditional cond).getCondition()
155-
or
156-
result = parent.(Conditional).getElse() and
157-
index = -1
158-
or
159-
result = getChild(parent.(Conditional), index) and
160-
not result = parent.(Conditional).getElse()
158+
not exists(Conditional cond | result = [cond.getElse(), cond.getThen()])
161159
or
162160
exists(Conditional cond |
163-
result = getConditionChild(cond, parent, index)
161+
parent = cond and
162+
result = cond.getElse() and
163+
index = -1
164164
or
165-
result = cond.getThen() and
166165
exists(int last |
167-
last = max(int i | exists(getConditionChild(cond, parent, i))) and
166+
result = cond.getThen() and
167+
last = max(int i | conditionHasChildAt(cond, parent, i)) and
168168
index = last + 1
169169
)
170170
)
@@ -247,6 +247,7 @@ module LocalNameBinding<LocationSig Location, LocalNameBindingInputSig<Location>
247247
* ```
248248
*/
249249
private AstNode getParentForScoping(AstNode n) {
250+
// n.getLocation().hasLocationInfo(any(string s | s.matches("%main.rs")), [112 .. 118], _, _, _) and
250251
not shouldBeShadowingDeclChild(_, _, _, n) and
251252
not exists(ShadowingDecl decl | n = [decl.getRhs(), decl.getElse()]) and
252253
n = getChildAdj(result, _)

0 commit comments

Comments
 (0)