diff options
-rw-r--r-- | changelog.md | 2 | ||||
-rw-r--r-- | script/parser/compile.lua | 27 | ||||
-rw-r--r-- | script/vm/operator.lua | 5 | ||||
-rw-r--r-- | test/type_inference/init.lua | 6 |
4 files changed, 27 insertions, 13 deletions
diff --git a/changelog.md b/changelog.md index daf246b3..c8df69db 100644 --- a/changelog.md +++ b/changelog.md @@ -8,6 +8,7 @@ * `FIX` [#1922] * `FIX` [#1924] * `FIX` [#1928] +* `FIX` [#1945] [#1715]: https://github.com/LuaLS/lua-language-server/issues/1715 [#1753]: https://github.com/LuaLS/lua-language-server/issues/1753 @@ -15,6 +16,7 @@ [#1922]: https://github.com/LuaLS/lua-language-server/issues/1922 [#1924]: https://github.com/LuaLS/lua-language-server/issues/1924 [#1928]: https://github.com/LuaLS/lua-language-server/issues/1928 +[#1945]: https://github.com/LuaLS/lua-language-server/issues/1945 ## 3.6.13 `2023-3-2` diff --git a/script/parser/compile.lua b/script/parser/compile.lua index 917a68a4..a33fe09b 100644 --- a/script/parser/compile.lua +++ b/script/parser/compile.lua @@ -1974,6 +1974,12 @@ local function parseSimple(node, funcName) and node.node == lastMethod then lastMethod = nil end + if node.type == 'call' then + if node.node.special == 'error' + or node.node.special == 'os.exit' then + node.hasExit = true + end + end if node == lastMethod then if funcName then lastMethod = nil @@ -2899,18 +2905,15 @@ local function compileExpAsAction(exp) end end - if exp.type == 'call' then - if exp.node.special == 'error' - or exp.node.special == 'os.exit' then - for i = #Chunk, 1, -1 do - local block = Chunk[i] - if block.type == 'ifblock' - or block.type == 'elseifblock' - or block.type == 'elseblock' - or block.type == 'function' then - block.hasExit = true - break - end + if exp.hasExit then + for i = #Chunk, 1, -1 do + local block = Chunk[i] + if block.type == 'ifblock' + or block.type == 'elseifblock' + or block.type == 'elseblock' + or block.type == 'function' then + block.hasExit = true + break end end return exp diff --git a/script/vm/operator.lua b/script/vm/operator.lua index cb27d33d..b2a3aa10 100644 --- a/script/vm/operator.lua +++ b/script/vm/operator.lua @@ -199,7 +199,10 @@ vm.binarySwitch = util.switch() elseif r1 == false then vm.setNode(source, node2) else - local node = node1:copy():setTruthy():merge(node2) + local node = node1:copy():setTruthy() + if not source[2].hasExit then + node:merge(node2) + end vm.setNode(source, node) end end) diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index 87e6c490..597fb761 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -4233,3 +4233,9 @@ function A:func() self.y = self.y + 3 end ]] + +TEST 'number' [[ +---@type number? +local n +local <?v?> = n or error('') +]] |