Skip to content

Commit 9baa655

Browse files
committed
fix #1107
1 parent 25a1c46 commit 9baa655

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* `CHG` dose not load files in symbol links
66
* `FIX` diagnostic: send empty results to every file after startup
77
* `FIX` [#1103](https://github.com/sumneko/lua-language-server/issues/1103)
8+
* `FIX` [#1107](https://github.com/sumneko/lua-language-server/issues/1107)
89

910
## 3.2.2
1011
`2022-4-26`

script/vm/node.lua

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ function mt:hasFalsy()
9696
for _, c in ipairs(self) do
9797
if c.type == 'nil'
9898
or (c.type == 'global' and c.cate == 'type' and c.name == 'nil')
99+
or (c.type == 'global' and c.cate == 'type' and c.name == 'false')
99100
or (c.type == 'boolean' and c[1] == false)
100101
or (c.type == 'doc.type.boolean' and c[1] == false) then
101102
return true
@@ -132,6 +133,7 @@ function mt:setTruthy()
132133
local c = self[index]
133134
if c.type == 'nil'
134135
or (c.type == 'global' and c.cate == 'type' and c.name == 'nil')
136+
or (c.type == 'global' and c.cate == 'type' and c.name == 'false')
135137
or (c.type == 'boolean' and c[1] == false)
136138
or (c.type == 'doc.type.boolean' and c[1] == false) then
137139
table.remove(self, index)
@@ -148,10 +150,7 @@ function mt:setTruthy()
148150
::CONTINUE::
149151
end
150152
if hasBoolean then
151-
self[#self+1] = {
152-
type = 'doc.type.boolean',
153-
[1] = true,
154-
}
153+
self[#self+1] = vm.declareGlobal('type', 'true')
155154
end
156155
end
157156

@@ -165,24 +164,21 @@ function mt:setFalsy()
165164
local c = self[index]
166165
if c.type == 'nil'
167166
or (c.type == 'global' and c.cate == 'type' and c.name == 'nil')
167+
or (c.type == 'global' and c.cate == 'type' and c.name == 'false')
168168
or (c.type == 'boolean' and c[1] == true)
169169
or (c.type == 'doc.type.boolean' and c[1] == true) then
170170
goto CONTINUE
171171
end
172172
if (c.type == 'global' and c.cate == 'type' and c.name == 'boolean')
173173
or (c.type == 'boolean' or c.type == 'doc.type.boolean') then
174174
hasBoolean = true
175-
goto CONTINUE
175+
table.remove(self, index)
176+
self[c] = nil
176177
end
177-
table.remove(self, index)
178-
self[c] = nil
179178
::CONTINUE::
180179
end
181180
if hasBoolean then
182-
self[#self+1] = {
183-
type = 'doc.type.boolean',
184-
[1] = false,
185-
}
181+
self[#self+1] = vm.declareGlobal('type', 'false')
186182
end
187183
end
188184

script/vm/value.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ function vm.test(source)
2020
hasFalse = true
2121
end
2222
end
23+
if n.type == 'global' and n.cate == 'type' then
24+
if n.name == 'true' then
25+
hasTrue = true
26+
end
27+
if n.name == 'false'
28+
or n.name == 'nil' then
29+
hasFalse = true
30+
end
31+
end
2332
if n.type == 'nil' then
2433
hasFalse = true
2534
end

test/type_inference/init.lua

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,3 +2273,27 @@ end
22732273
22742274
print(<?x?>)
22752275
]]
2276+
2277+
TEST 'true' [[
2278+
---@type boolean
2279+
local t
2280+
2281+
if t then
2282+
print(<?t?>)
2283+
return
2284+
end
2285+
2286+
print(t)
2287+
]]
2288+
2289+
TEST 'false' [[
2290+
---@type boolean
2291+
local t
2292+
2293+
if t then
2294+
print(t)
2295+
return
2296+
end
2297+
2298+
print(<?t?>)
2299+
]]

0 commit comments

Comments
 (0)