Skip to content

Commit f5fcab0

Browse files
committed
support ---@type and --[[@as]] for return
resolve #2144
1 parent 5e5a1b2 commit f5fcab0

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# changelog
22

33
## 3.7.0
4+
* `NEW` support `---@type` and `--[[@as]]` for return statement
45
* `FIX` wrong hover and signature for method with varargs and overloads
56
* `FIX` [#2224]
67

script/vm/compiler.lua

+10
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,16 @@ local compilerSwitch = util.switch()
11681168
vm.compileCallArg(source, call)
11691169
end
11701170

1171+
if source.parent.type == 'return' then
1172+
local myIndex = util.arrayIndexOf(source.parent, source)
1173+
---@cast myIndex -?
1174+
local parentNode = vm.selectNode(source.parent, myIndex)
1175+
if not parentNode:isEmpty() then
1176+
vm.setNode(source, parentNode)
1177+
return
1178+
end
1179+
end
1180+
11711181
if source.parent.type == 'setglobal'
11721182
or source.parent.type == 'local'
11731183
or source.parent.type == 'setlocal'

test/diagnostics/missing-fields.lua

+8
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,11 @@ local b = {
197197
c = 3,
198198
}
199199
]]
200+
201+
TEST [[
202+
---@class A
203+
---@field x integer
204+
205+
---@type A
206+
return <!{}!>
207+
]]

0 commit comments

Comments
 (0)