Skip to content

Commit

Permalink
Fix false positive for "variable is mutated but never accessed"
Browse files Browse the repository at this point in the history
When value or variable is assigned a result of an operation such as
"and" or "or", it is externally accessible and mutations of it
may have an effect even if it is not directly accessed. Same
if value node tag is Paren (e.g. `local t = (f())`).

Ref #72.
  • Loading branch information
mpeterv committed Sep 28, 2016
1 parent 49c3ec2 commit 1e62378
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions spec/check_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ elseif (...)[2] then
elseif (...)[3] then
a = b()
a.k3 = 3
elseif (...)[4] then
a = b(1) or b(2)
a.k4 = 4
else
a = {}
return a
Expand Down
2 changes: 1 addition & 1 deletion src/luacheck/analyze.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ local function is_function_var(var)
#var.values == 2 and var.values[1].empty and var.values[2].type == "func")
end

local externally_accessible_tags = utils.array_to_set({"Id", "Index", "Call", "Invoke", "Dots"})
local externally_accessible_tags = utils.array_to_set({"Id", "Index", "Call", "Invoke", "Op", "Paren", "Dots"})

local function externally_accessible(value)
return value.type ~= "var" or (value.node and externally_accessible_tags[value.node.tag])
Expand Down

0 comments on commit 1e62378

Please sign in to comment.