Skip to content

Commit d0d4d7c

Browse files
committed
unified: Ensure parameter defaults resolve correctly
1 parent 9f8745b commit d0d4d7c

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,17 @@ private module LocalNameBindingInput implements LocalNameBindingInputSig<Locatio
203203
declaration = func
204204
)
205205
or
206-
exists(Parameter param |
207-
scope = param.getDeclaringCallable() and
206+
exists(Parameter param, Callable callable |
207+
callable = param.getDeclaringCallable() and
208+
(
209+
// Scope to the body so parameter defaults cannot see the parameter list
210+
// TODO: Use a plugin for languages where parameter defaults can reference earlier parameters
211+
scope = callable.getBody()
212+
or
213+
// For bodyless functions, choose an arbitrary scope
214+
not exists(callable.getBody()) and
215+
scope = param
216+
) and
208217
pattern = param.getPattern() and
209218
declaration = param
210219
)

‎unified/ql/test/library-tests/local-name-binding/test.swift‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,9 @@ func t41() {
397397
// This function and its parameter have the same name
398398
// The parameter default value must resolve to the outer name (the function)
399399
// swift-format-ignore
400-
func foo( // name=foo1
400+
func foo( // $ captured=foo1 // name=foo1
401401
_ foo: Any = // name=foo2
402-
foo // $ MISSING: access=foo1 SPURIOUS: access=foo2
402+
foo // $ access=foo1
403403
) {
404404
foo // $ access=foo2
405405
}

0 commit comments

Comments
 (0)