diff options
-rw-r--r-- | changelog.md | 11 | ||||
-rw-r--r-- | script/vm/compiler.lua | 6 | ||||
-rw-r--r-- | test/type_inference/init.lua | 10 |
3 files changed, 27 insertions, 0 deletions
diff --git a/changelog.md b/changelog.md index 87086803..07f0bc5c 100644 --- a/changelog.md +++ b/changelog.md @@ -93,6 +93,16 @@ server will generate `doc.json` and `doc.md` in `LOGPATH`. end end ``` +* `CHG` [#1332] infer parameter type when function in table + ```lua + ---@class A + ---@field f fun(x: string) + + ---@type A + local t = { + f = function (x) end --> `x` is inferred as `string` + } + ``` * `CHG` find reference: respect `includeDeclaration` (although I don't know how to turn off this option in VSCode) * `FIX` [#1567] * `FIX` [#1593] @@ -107,6 +117,7 @@ server will generate `doc.json` and `doc.md` in `LOGPATH`. [#1153]: https://github.com/sumneko/lua-language-server/issues/1153 [#1177]: https://github.com/sumneko/lua-language-server/issues/1177 [#1202]: https://github.com/sumneko/lua-language-server/issues/1202 +[#1332]: https://github.com/sumneko/lua-language-server/issues/1332 [#1458]: https://github.com/sumneko/lua-language-server/issues/1458 [#1557]: https://github.com/sumneko/lua-language-server/issues/1557 [#1558]: https://github.com/sumneko/lua-language-server/issues/1558 diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 52f1083b..03a34dbd 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -1108,6 +1108,12 @@ local compilerSwitch = util.switch() end end end + + -- { f = function (<?x?>) end } + if source.parent.type == 'tablefield' + or source.parent.type == 'tableindex' then + vm.setNode(source, vm.compileNode(source.parent)) + end end) : case 'paren' : call(function (source) diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index 33704c1a..0419ed9b 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -3866,3 +3866,13 @@ local function f() end end ]] + +TEST 'string' [[ +---@class A +---@field f fun(x: string) + +---@type A +local t = { + f = function (<?x?>) end +} +]] |