Skip to content

Commit dbebb42

Browse files
committed
check: named vararg table is <const>
Fixes #1160
1 parent 2a5cafd commit dbebb42

5 files changed

Lines changed: 15 additions & 5 deletions

File tree

spec/lang/declaration/local_function_spec.lua

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ describe("local function", function()
129129
]]))
130130
end)
131131

132-
describe("Lua 5.5 named variadic arguments", function()
132+
describe("Lua 5.5-style named variadic arguments", function()
133133
it("works in a type annotation", util.check([[
134134
local _: function(a: integer, ...b: integer)
135135
]]))
@@ -166,6 +166,16 @@ describe("local function", function()
166166
167167
f(1, 2, 3, 4)
168168
]])
169+
170+
it("the named vararg table is <const>", util.check_type_error([[
171+
local function test(...args: boolean): integer, boolean
172+
args[1] = false
173+
args = { true }
174+
return args.n, args[1]
175+
end
176+
]], {
177+
{ y = 3, msg = "cannot assign to <const> variable" }
178+
}))
169179
end)
170180

171181
it("declaration", util.check([[

teal.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9597,7 +9597,7 @@ visit_node.cbs = {
95979597
local generic_pack_table = (table_t.fields["PackTable"]).def
95989598
local pack_table = self:apply_generic(node, generic_pack_table, { t })
95999599

9600-
self:add_var(node, node.name.tk, pack_table).is_func_arg = true
9600+
self:add_var(node, node.name.tk, pack_table, "const").is_func_arg = true
96019601
is_named_vararg = true
96029602
end
96039603
t = a_vararg(node, { t })

teal/check/visitors.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2328,7 +2328,7 @@ visit_node.cbs = {
23282328
local generic_pack_table = (table_t.fields["PackTable"]).def
23292329
local pack_table = self:apply_generic(node, generic_pack_table, { t })
23302330

2331-
self:add_var(node, node.name.tk, pack_table).is_func_arg = true
2331+
self:add_var(node, node.name.tk, pack_table, "const").is_func_arg = true
23322332
is_named_vararg = true
23332333
end
23342334
t = a_vararg(node, { t })

teal/check/visitors.tl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2328,7 +2328,7 @@ visit_node.cbs = {
23282328
local generic_pack_table <const> = (table_t.fields["PackTable"] as types.TypeDeclType).def as types.GenericType
23292329
local pack_table <const> = self:apply_generic(node, generic_pack_table, { t })
23302330

2331-
self:add_var(node, node.name.tk, pack_table).is_func_arg = true
2331+
self:add_var(node, node.name.tk, pack_table, "const").is_func_arg = true
23322332
is_named_vararg = true
23332333
end
23342334
t = a_vararg(node, { t })

tl.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9851,7 +9851,7 @@ visit_node.cbs = {
98519851
local generic_pack_table = (table_t.fields["PackTable"]).def
98529852
local pack_table = self:apply_generic(node, generic_pack_table, { t })
98539853

9854-
self:add_var(node, node.name.tk, pack_table).is_func_arg = true
9854+
self:add_var(node, node.name.tk, pack_table, "const").is_func_arg = true
98559855
is_named_vararg = true
98569856
end
98579857
t = a_vararg(node, { t })

0 commit comments

Comments
 (0)