You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect "no visible binding for global variable" #666
I think the problem lies in the get_assignment_symbols function: it returns c( "foo", "foo", "$", "bar", "zero") as left_assignment_symbols. If I edit that to return just c("foo", "zero"), I don't get the false positive.
I think it needs a predicate saying that expr[1] is a SYMBOL, not an expression like foo$bar. Unfortunately, I don't know XML well enough to know how to write that.
The *[1] makes sure we're inside the LHS of the assignment operator and descendant-or-self::SYMBOL[1] ensures we only take the first SYMBOL element per result.
Activity
AshesITR commentedon Dec 4, 2020
Confirmed. The problem lies somewhere in the way
object_usage_linterusescodetools::checkUsage().dmurdoch commentedon Jan 7, 2021
I think the problem lies in the
get_assignment_symbolsfunction: it returnsc( "foo", "foo", "$", "bar", "zero")asleft_assignment_symbols. If I edit that to return justc("foo", "zero"), I don't get the false positive.Here's the line that produces the bad result:
I think it needs a predicate saying that
expr[1]is aSYMBOL, not an expression likefoo$bar. Unfortunately, I don't know XML well enough to know how to write that.AshesITR commentedon Jan 7, 2021
@dmurdoch Thanks for the hint.
I've figured out an XPath that should always work for
a$b$c$d-chains (returninga) as well as direct assignments:The
*[1]makes sure we're inside the LHS of the assignment operator anddescendant-or-self::SYMBOL[1]ensures we only take the first SYMBOL element per result.only extract the first symbol for equal and left assignments
dmurdoch commentedon Jan 8, 2021
That appears to miss complex assignments like
names(x) <- "y". But I don't understand the code well enough to know if this would be a problem.AshesITR commentedon Jan 8, 2021
Hmm I see. Maybe a better Idea would be to check that the parent expression is no DOLLAR-OP...
russHyde commentedon Jan 26, 2021
The same bug occured in #445 (which I have closed to remove duplicate issues)
AshesITR commentedon Jan 26, 2021
@russHyde do you mind taking a look at #709?
I'm not sure whether the changed XPath works for all possible assignments.
russHyde commentedon Jan 27, 2021
Sure. I'm not an XPath expert by any means. I can compare object-usage over some packages before/after your changes if that's helpful.
AshesITR commentedon Jan 27, 2021
That would be very useful indeed.
Seeing no observable side-effects would increase my confidence in the XPath-fu job.
only extract the first symbol for equal and left assignments (#709)