Skip to content

Commit

Permalink
Remove 'vararg' warning property
Browse files Browse the repository at this point in the history
Check .name == "..." instead.
  • Loading branch information
mpeterv committed Jul 12, 2015
1 parent f91150b commit 676b440
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 19 deletions.
4 changes: 2 additions & 2 deletions spec/cache_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe("cache", function()
describe("serialize", function()
it("returns serialized result", function()
assert.same(
'return {{"111","foo",5,100,[24]=true},{"211","bar",4,1,[7]=true,[11]=true},{[3]=5,[4]=100000,[14]=true}}',
'return {{"111","foo",5,100,[23]=true},{"211","bar",4,1,[7]=true,[10]=true},{[3]=5,[4]=100000,[13]=true}}',
cache.serialize({
{code = "111", name = "foo", line = 5, column = 100, in_module = true},
{code = "211", name = "bar", line = 4, column = 1, secondary = true, filtered = true},
Expand All @@ -16,7 +16,7 @@ describe("cache", function()

it("puts repeating string values into locals", function()
assert.same(
'local A,B="111","foo";return {{A,B,5,100,[24]=true},{A,B,6,100,[7]=true,[11]=true},{[3]=5,[4]=100000,[14]=true}}',
'local A,B="111","foo";return {{A,B,5,100,[23]=true},{A,B,6,100,[7]=true,[10]=true},{[3]=5,[4]=100000,[13]=true}}',
cache.serialize({
{code = "111", name = "foo", line = 5, column = 100, in_module = true},
{code = "111", name = "foo", line = 6, column = 100, secondary = true, filtered = true},
Expand Down
2 changes: 1 addition & 1 deletion spec/check_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ print(foo)
it("detects redefinition of function arguments", function()
assert.same({
{code = "212", name = "foo", line = 1, column = 17},
{code = "212", name = "...", line = 1, column = 22, vararg = true},
{code = "212", name = "...", line = 1, column = 22},
{code = "412", name = "foo", line = 2, column = 10, prev_line = 1, prev_column = 17}
}, check[[
return function(foo, ...)
Expand Down
2 changes: 1 addition & 1 deletion spec/cli_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ Total: 5 warnings / 1 error in 3 files
return {}
spec/samples/bad_code.lua
(%d+)
local A="113";return {{A,"package",1,1},{"211","helper",3,16,%[9%]=true},{"212","...",3,23,%[10%]=true},{"111","embrace",7,10,%[12%]=true},{"412","opt",8,10,7,18},{A,"hepler",9,11}}
local A="113";return {{A,"package",1,1},{"211","helper",3,16,%[9%]=true},{"212","...",3,23},{"111","embrace",7,10,%[11%]=true},{"412","opt",8,10,7,18},{A,"hepler",9,11}}
spec/samples/python_code.lua
(%d+)
return {1,6,6,"expected '=' near '__future__'"}
Expand Down
14 changes: 7 additions & 7 deletions spec/linearize_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,12 @@ end]]))
describe("when registering values", function()
it("registers values in empty chunk correctly", function()
assert.equal([[
Local: ... (vararg / vararg, initial)]], get_value_info_as_string(""))
Local: ... (arg / arg, initial)]], get_value_info_as_string(""))
end)

it("registers values in assignments correctly", function()
assert.equal([[
Local: ... (vararg / vararg, initial)
Local: ... (arg / arg, initial)
Local: a (var / var, initial)
Set: a (var / var)]], get_value_info_as_string([[
local a = b
Expand All @@ -304,7 +304,7 @@ a = d]]))

it("registers empty values correctly", function()
assert.equal([[
Local: ... (vararg / vararg, initial)
Local: ... (arg / arg, initial)
Local: a (var / var, initial), b (var / var, empty)
Set: a (var / var), b (var / var)]], get_value_info_as_string([[
local a, b = 4
Expand All @@ -313,22 +313,22 @@ a, b = 5]]))

it("registers function values as of type func", function()
assert.equal([[
Local: ... (vararg / vararg, initial)
Local: ... (arg / arg, initial)
Local: f (var / func, initial)]], get_value_info_as_string([[
local function f() end]]))
end)

it("registers overwritten args and counters as of type var", function()
assert.equal([[
Local: ... (vararg / vararg, initial)
Local: ... (arg / arg, initial)
Local: i (loopi / loopi, initial)
Set: i (loopi / var)]], get_value_info_as_string([[
for i = 1, 10 do i = 6 end]]))
end)

it("registers groups of secondary values", function()
assert.equal([[
Local: ... (vararg / vararg, initial)
Local: ... (arg / arg, initial)
Local: a (var / var, initial), b (var / var, initial, 2 secondaries), c (var / var, initial, 2 secondaries)
Set: a (var / var), b (var / var, 2 secondaries), c (var / var, 2 secondaries)]], get_value_info_as_string([[
local a, b, c = f(), g()
Expand All @@ -337,7 +337,7 @@ a, b, c = f(), g()]]))

it("marks groups of secondary values used if one of values is put into global or index", function()
assert.equal([[
Local: ... (vararg / vararg, initial)
Local: ... (arg / arg, initial)
Local: a (var / var, empty)
Set: a (var / var, 1 secondaries, used)]], get_value_info_as_string([[
local a
Expand Down
3 changes: 1 addition & 2 deletions spec/luacheck_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ describe("luacheck", function()
code = "212",
name = "...",
line = 3,
column = 23,
vararg = true
column = 23
},
{
code = "111",
Expand Down
2 changes: 1 addition & 1 deletion src/luacheck/cache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ local cache = {}

local fields = {
"code", "name", "line", "column", "prev_line", "prev_column", "secondary", "self", "func",
"vararg", "filtered", "top", "invalid", "unpaired", "read_only", "global", "filtered_111",
"filtered", "top", "invalid", "unpaired", "read_only", "global", "filtered_111",
"filtered_121", "filtered_131", "filtered_112", "filtered_122", "filtered_113", "definition",
"in_module"}

Expand Down
4 changes: 1 addition & 3 deletions src/luacheck/check.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ local type_codes = {
var = 1,
func = 1,
arg = 2,
vararg = 2,
loop = 3,
loopi = 3
}
Expand All @@ -55,8 +54,7 @@ function ChState:warn_unused_variable(var)
column = var.location.column,
secondary = is_secondary(var.values[1]) or nil,
func = (var.values[1].type == "func") or nil,
self = var.self,
vararg = (var.type == "vararg") or nil
self = var.self
})
end

Expand Down
2 changes: 1 addition & 1 deletion src/luacheck/format.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ local message_formats = {
if w.func then return "unused function %s"
else return "unused variable %s" end end,
["212"] = function(w)
if w.vararg then return "unused variable length argument"
if w.name == "..." then return "unused variable length argument"
else return "unused argument %s" end end,
["213"] = "unused loop variable %s",
["221"] = "variable %s is never set",
Expand Down
2 changes: 1 addition & 1 deletion src/luacheck/linearize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ local function new_var(line, node, type_)
return {
name = node[1],
location = node.location,
type = (node[1] == "...") and "vararg" or type_,
type = type_,
self = node.implicit,
line = line,
scope_start = line.items.size + 1,
Expand Down

0 comments on commit 676b440

Please sign in to comment.