Skip to content

Commit

Permalink
Fix circular reference detection to notice that OpSet passes around l…
Browse files Browse the repository at this point in the history
…hs/rhs as a single var, not multiple
  • Loading branch information
arichard4 committed Dec 17, 2022
1 parent 83e1969 commit c899b72
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docsrc/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Option Meaning
``--ignore | -i <patt> [<patt>] ...`` Filter out warnings matching patterns.
``--enable | -e <patt> [<patt>] ...`` Do not filter out warnings matching patterns.
``--only | -o <patt> [<patt>] ...`` Filter out warnings not matching patterns.
``--operators <patt> [<patt>] ...`` Allow compound operators matching patterns.
``--operators <patt> [<patt>] ...`` Allow compound operators matching patterns. (Multiple assignment not supported, as this is specifically for the Playdate SDK.)
``--config <config>`` Path to custom configuration file (default: ``.luacheckrc``).
``--no-config`` Do not look up custom configuration file.
``--default-config <config>`` Default path to custom configuration file, to be used if ``--[no-]config`` is not used and ``.luacheckrc`` is not found.
Expand Down
6 changes: 3 additions & 3 deletions src/luacheck/stages/resolve_locals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,18 @@ end

local function is_circular_reference(item, var)
-- No support for matching multiple assignment to the specific assignment
if not item.lhs or #item.lhs ~= 1 or not item.rhs or #item.rhs ~= 1 then
if not (item.tag == "Set" or item.tag == "Local" or item.tag == "OpSet") then
return false
end

-- Case t[t.function()] = t.func()
-- Functions can have side-effects, so this isn't purely circular
local right_assignment = item.rhs[1]
local right_assignment = item.tag == "OpSet" and item.rhs or item.rhs[1]
if contains_call(right_assignment) then
return false
end

local left_assignment = item.lhs[1]
local left_assignment = item.tag == "OpSet" and item.lhs or item.lhs[1]
if contains_call(left_assignment) then
return false
end
Expand Down

0 comments on commit c899b72

Please sign in to comment.