Skip to content

Commit

Permalink
Fix circular reference detection to note that all OpSets are circular…
Browse files Browse the repository at this point in the history
… references
  • Loading branch information
arichard4 committed Jun 5, 2023
1 parent 9b9764d commit bb9e7f6
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/luacheck/stages/resolve_locals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,24 @@ local function contains_call(node)
end

local function is_circular_reference(item, var)
-- OpSet is circular by definition
if not (item.tag == "Set" or item.tag == "Local") then
return false
end

-- No support for matching multiple assignment to the specific assignment
if not (item.tag == "Set" or item.tag == "Local" or item.tag == "OpSet") then
if not item.lhs or #item.lhs ~= 1 or not item.rhs or #item.rhs ~= 1 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.tag == "OpSet" and item.rhs or item.rhs[1]
local right_assignment = item.rhs[1]
if contains_call(right_assignment) then
return false
end

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

0 comments on commit bb9e7f6

Please sign in to comment.