-
Notifications
You must be signed in to change notification settings - Fork 29
check for unused bindings #255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
function is_overwritten_in_loop(x) | ||
# Cuts out false positives for check_unused_binding - the linear nature of our | ||
# semantic passes mean a variable declared at the end of a loop's block but used at | ||
# the start won't appear to be referenced. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, but isn't that in line with how Julia's loops work?
julia> for i in 1:3
if i > 2
println(x)
end
x = i
end
ERROR: UndefVarError: x not defined
So we only need to check if the variable being assigned is used in a enclosing scope, as you mention below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, that i did not know!
EDIT: Though thankfully the it doesn't actually check this. For info, these checks don't run on the toplevel scope so you need to wrap the above example in a function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't matter whether it's in a top-level scope or not, afaict:
julia> function f()
for i in 1:3
if i > 2
println(x)
end
x=i
end
end
f (generic function with 1 method)
julia> f()
ERROR: UndefVarError: x not defined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant for the StaticLint checks
Needs some finessing: