diff options
-rw-r--r-- | changelog.md | 2 | ||||
-rw-r--r-- | script/vm/compiler.lua | 15 | ||||
-rw-r--r-- | test/crossfile/infer.lua | 30 |
3 files changed, 47 insertions, 0 deletions
diff --git a/changelog.md b/changelog.md index 2119b4e7..39207a62 100644 --- a/changelog.md +++ b/changelog.md @@ -2,8 +2,10 @@ ## 3.6.9 * `FIX` [#1864] +* `FIX` [#1868] [#1864]: https://github.com/sumneko/lua-language-server/issues/1864 +[#1868]: https://github.com/sumneko/lua-language-server/issues/1868 ## 3.6.8 `2023-1-31` diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 3bebbc20..4f97b0e0 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -1484,6 +1484,21 @@ local compilerSwitch = util.switch() return end if func.special == 'require' then + if index == 2 then + local uri = guide.getUri(source) + local version = config.get(uri, 'Lua.runtime.version') + if version == 'Lua 5.3' + or version == 'Lua 5.4' then + vm.setNode(source, vm.declareGlobal('type', 'unknown')) + else + vm.setNode(source, vm.declareGlobal('type', 'nil')) + end + return + end + if index >= 3 then + vm.setNode(source, vm.declareGlobal('type', 'nil')) + return + end if not args then return end diff --git a/test/crossfile/infer.lua b/test/crossfile/infer.lua index 0b458e5f..de29007b 100644 --- a/test/crossfile/infer.lua +++ b/test/crossfile/infer.lua @@ -133,3 +133,33 @@ print(<?X?>) ]], }, infer = 'boolean|integer', } + +TEST { + { path = 'a.lua', content = [[ +return 1337, "string", true +]], }, + { path = 'b.lua', content = [[ +local <?a?>, b, c = require 'a +]], }, + infer = 'integer', +} + +TEST { + { path = 'a.lua', content = [[ +return 1337, "string", true +]], }, + { path = 'b.lua', content = [[ +local a, <?b?>, c = require 'a +]], }, + infer = 'unknown', +} + +TEST { + { path = 'a.lua', content = [[ +return 1337, "string", true +]], }, + { path = 'b.lua', content = [[ +local a, b, <?c?> = require 'a +]], }, + infer = 'nil', +} |