diff options
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | script/vm/infer.lua | 9 | ||||
-rw-r--r-- | script/vm/node.lua | 24 | ||||
-rw-r--r-- | test/hover/init.lua | 21 |
4 files changed, 48 insertions, 7 deletions
diff --git a/changelog.md b/changelog.md index c7f1556e..bd1cede4 100644 --- a/changelog.md +++ b/changelog.md @@ -13,6 +13,7 @@ ``` * `NEW` diagnostics: * `unknown-operator` +* `FIX` [#1294](https://github.com/sumneko/lua-language-server/issues/1294) ## 3.4.2 `2022-7-6` diff --git a/script/vm/infer.lua b/script/vm/infer.lua index 94538a79..263b2500 100644 --- a/script/vm/infer.lua +++ b/script/vm/infer.lua @@ -477,7 +477,14 @@ function mt:viewLiterals() if #literals == 0 then return nil end - table.sort(literals) + table.sort(literals, function (a, b) + local sa = inferSorted[a] or 0 + local sb = inferSorted[b] or 0 + if sa == sb then + return a < b + end + return sa < sb + end) return table.concat(literals, '|') end diff --git a/script/vm/node.lua b/script/vm/node.lua index d84b7030..65a2108f 100644 --- a/script/vm/node.lua +++ b/script/vm/node.lua @@ -162,17 +162,23 @@ function mt:setTruthy() self[c] = nil goto CONTINUE end - if (c.type == 'global' and c.cate == 'type' and c.name == 'boolean') - or (c.type == 'boolean' or c.type == 'doc.type.boolean') then + if c.type == 'global' and c.cate == 'type' and c.name == 'boolean' then hasBoolean = true table.remove(self, index) self[c] = nil goto CONTINUE end + if c.type == 'boolean' or c.type == 'doc.type.boolean' then + if c[1] == false then + table.remove(self, index) + self[c] = nil + goto CONTINUE + end + end ::CONTINUE:: end if hasBoolean then - self[#self+1] = vm.declareGlobal('type', 'true') + self:merge(vm.declareGlobal('type', 'true')) end return self end @@ -192,13 +198,19 @@ function mt:setFalsy() or (c.type == 'doc.type.boolean' and c[1] == false) then goto CONTINUE end - if (c.type == 'global' and c.cate == 'type' and c.name == 'boolean') - or (c.type == 'boolean' or c.type == 'doc.type.boolean') then + if c.type == 'global' and c.cate == 'type' and c.name == 'boolean' then hasBoolean = true table.remove(self, index) self[c] = nil goto CONTINUE end + if c.type == 'boolean' or c.type == 'doc.type.boolean' then + if c[1] == true then + table.remove(self, index) + self[c] = nil + goto CONTINUE + end + end if (c.type == 'global' and c.cate == 'type') then table.remove(self, index) self[c] = nil @@ -207,7 +219,7 @@ function mt:setFalsy() ::CONTINUE:: end if hasBoolean then - self[#self+1] = vm.declareGlobal('type', 'false') + self:merge(vm.declareGlobal('type', 'false')) end return self end diff --git a/test/hover/init.lua b/test/hover/init.lua index 476644fc..82cf1ddf 100644 --- a/test/hover/init.lua +++ b/test/hover/init.lua @@ -2091,3 +2091,24 @@ end a: integer = 1, } ]] + +TEST [[ +local y +if X then + y = true +else + y = false +end + +local bool = y + +bool = bool and y + +if bool then +end + +print(<?bool?>) +]] +[[ +local bool: boolean = true|false +]] |