Skip to content

Commit b404f2d

Browse files
committed
fix implicit return with decorated statements
1 parent 063b50a commit b404f2d

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

moonscript/transform.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,10 @@ implicitly_return = function(scope)
12281228
local fn
12291229
fn = function(stm)
12301230
local t = ntype(stm)
1231+
if t == "decorated" then
1232+
stm = scope.transform.statement(stm)
1233+
t = ntype(stm)
1234+
end
12311235
if types.manual_return[t] or not types.is_value(stm) then
12321236
if is_top and t == "return" and stm[2] == "" then
12331237
return nil

moonscript/transform.moon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,12 @@ implicitly_return = (scope) ->
627627
is_top = true
628628
fn = (stm) ->
629629
t = ntype stm
630+
631+
-- expand decorated
632+
if t == "decorated"
633+
stm = scope.transform.statement stm
634+
t = ntype stm
635+
630636
if types.manual_return[t] or not types.is_value stm
631637
-- remove blank return statement
632638
if is_top and t == "return" and stm[2] == ""

tests/inputs/funcs.moon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ y -> return 1
5757
z -> return 1, "hello", "world"
5858
k -> if yes then return else return
5959

60-
60+
-> real_name if something
6161

tests/outputs/funcs.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,9 @@ k(function()
107107
else
108108
return
109109
end
110-
end)
110+
end)
111+
_ = function()
112+
if something then
113+
return real_name
114+
end
115+
end

0 commit comments

Comments
 (0)