Skip to content

Commit 7752760

Browse files
committed
@@variables should be assignable
1 parent f98f822 commit 7752760

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

moonscript/parse.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,12 @@ local function flatten_or_mark(name)
165165
end
166166

167167
-- makes sure the last item in a chain is an index
168-
local _assignable = { index = true, dot = true, slice = true }
168+
local _chain_assignable = { index = true, dot = true, slice = true }
169169

170170
local function is_assignable(node)
171171
local t = ntype(node)
172-
return t == "self" or t == "value" or
173-
t == "chain" and _assignable[ntype(node[#node])]
172+
return t == "self" or t == "value" or t == "self_class" or
173+
t == "chain" and _chain_assignable[ntype(node[#node])]
174174
end
175175

176176
local function check_assignable(str, pos, value)
@@ -188,7 +188,6 @@ local function format_assign(lhs_exps, assign)
188188

189189
for _, assign_exp in ipairs(lhs_exps) do
190190
if not is_assignable(assign_exp) then
191-
print(util.dump(assign_exp))
192191
error {assign_exp, "left hand expression is not assignable"}
193192
end
194193
end

tests/inputs/syntax.moon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ y /= 100
142142
m %= 2
143143
hello ..= "world"
144144

145+
@@something += 10
146+
@something += 10
147+
145148
x = 0
146149
(if ntype(v) == "fndef" then x += 1) for v in *values
147150

tests/outputs/syntax.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ y = y * 2
149149
y = y / 100
150150
local m = m % 2
151151
local hello = hello .. "world"
152+
self.__class.something = self.__class.something + 10
153+
self.something = self.something + 10
152154
x = 0
153155
local _list_0 = values
154156
for _index_0 = 1, #_list_0 do

0 commit comments

Comments
 (0)