diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-07-07 16:04:02 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-07-07 16:04:02 +0800 |
commit | 3150962ceadf0046deb164ab6e042f74029de4eb (patch) | |
tree | 2f585975bd6b744d197b78e6c5d12cccc4a162c6 /script | |
parent | f5464ddc9a8e043977f27e70d9f1dfc2be56b02e (diff) | |
download | lua-language-server-3150962ceadf0046deb164ab6e042f74029de4eb.zip |
fix #1294
Diffstat (limited to 'script')
-rw-r--r-- | script/vm/infer.lua | 9 | ||||
-rw-r--r-- | script/vm/node.lua | 24 |
2 files changed, 26 insertions, 7 deletions
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 |