@@variables should be assignable

This commit is contained in:
leaf corcoran 2012-11-02 09:12:05 -07:00
parent f98f822891
commit 7752760160
3 changed files with 8 additions and 4 deletions

View File

@ -165,12 +165,12 @@ local function flatten_or_mark(name)
end end
-- makes sure the last item in a chain is an index -- makes sure the last item in a chain is an index
local _assignable = { index = true, dot = true, slice = true } local _chain_assignable = { index = true, dot = true, slice = true }
local function is_assignable(node) local function is_assignable(node)
local t = ntype(node) local t = ntype(node)
return t == "self" or t == "value" or return t == "self" or t == "value" or t == "self_class" or
t == "chain" and _assignable[ntype(node[#node])] t == "chain" and _chain_assignable[ntype(node[#node])]
end end
local function check_assignable(str, pos, value) local function check_assignable(str, pos, value)
@ -188,7 +188,6 @@ local function format_assign(lhs_exps, assign)
for _, assign_exp in ipairs(lhs_exps) do for _, assign_exp in ipairs(lhs_exps) do
if not is_assignable(assign_exp) then if not is_assignable(assign_exp) then
print(util.dump(assign_exp))
error {assign_exp, "left hand expression is not assignable"} error {assign_exp, "left hand expression is not assignable"}
end end
end end

View File

@ -142,6 +142,9 @@ y /= 100
m %= 2 m %= 2
hello ..= "world" hello ..= "world"
@@something += 10
@something += 10
x = 0 x = 0
(if ntype(v) == "fndef" then x += 1) for v in *values (if ntype(v) == "fndef" then x += 1) for v in *values

View File

@ -149,6 +149,8 @@ y = y * 2
y = y / 100 y = y / 100
local m = m % 2 local m = m % 2
local hello = hello .. "world" local hello = hello .. "world"
self.__class.something = self.__class.something + 10
self.something = self.something + 10
x = 0 x = 0
local _list_0 = values local _list_0 = values
for _index_0 = 1, #_list_0 do for _index_0 = 1, #_list_0 do