summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md1
-rw-r--r--script/vm/compiler.lua10
-rw-r--r--test/diagnostics/missing-fields.lua8
3 files changed, 19 insertions, 0 deletions
diff --git a/changelog.md b/changelog.md
index 78810cb8..8cbfc1d2 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,6 +1,7 @@
# changelog
## 3.7.0
+* `NEW` support `---@type` and `--[[@as]]` for return statement
* `FIX` wrong hover and signature for method with varargs and overloads
* `FIX` [#2224]
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 543ee0d4..7faa4f47 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -1168,6 +1168,16 @@ local compilerSwitch = util.switch()
vm.compileCallArg(source, call)
end
+ if source.parent.type == 'return' then
+ local myIndex = util.arrayIndexOf(source.parent, source)
+ ---@cast myIndex -?
+ local parentNode = vm.selectNode(source.parent, myIndex)
+ if not parentNode:isEmpty() then
+ vm.setNode(source, parentNode)
+ return
+ end
+ end
+
if source.parent.type == 'setglobal'
or source.parent.type == 'local'
or source.parent.type == 'setlocal'
diff --git a/test/diagnostics/missing-fields.lua b/test/diagnostics/missing-fields.lua
index d8731775..f5fdd35c 100644
--- a/test/diagnostics/missing-fields.lua
+++ b/test/diagnostics/missing-fields.lua
@@ -197,3 +197,11 @@ local b = {
c = 3,
}
]]
+
+TEST [[
+---@class A
+---@field x integer
+
+---@type A
+return <!{}!>
+]]