Skip to content

Commit c2fb1d5

Browse files
committed
fix #1228 doc.as may not work
1 parent 830165b commit c2fb1d5

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

Diff for: changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
local n2 = f(0) -- `n2` is `number`
2424
local n3 = f(0, 0) -- `n3` is `string`
2525
```
26+
* `FIX` [#1228](https://github.com/sumneko/lua-language-server/issues/1228)
2627

2728
## 3.3.1
2829
`2022-6-17`

Diff for: script/vm/compiler.lua

+7-6
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ local function bindAs(source)
629629
local root = guide.getRoot(source)
630630
local docs = root.docs
631631
if not docs then
632-
return
632+
return false
633633
end
634634
local ases = docs._asCache
635635
if not ases then
@@ -645,19 +645,20 @@ local function bindAs(source)
645645
end)
646646
end
647647

648+
if #ases == 0 then
649+
return false
650+
end
651+
648652
local max = #ases
649653
local index
650654
local left = 1
651655
local right = max
652656
for _ = 1, 1000 do
653-
index = left + (right - left) // 2
654-
if index <= left then
657+
if left == right then
655658
index = left
656659
break
657-
elseif index >= right then
658-
index = right
659-
break
660660
end
661+
index = left + (right - left) // 2
661662
local doc = ases[index]
662663
if doc.originalComment.start < source.finish + 2 then
663664
left = index + 1

Diff for: test/type_inference/init.lua

+6
Original file line numberDiff line numberDiff line change
@@ -2998,3 +2998,9 @@ local t
29982998
29992999
local <?n?> = t[i]
30003000
]]
3001+
3002+
TEST 'string' [=[
3003+
local x = true
3004+
local y = x--[[@as integer]] --is `integer` here
3005+
local z = <?x?>--[[@as string]] --is `true` here
3006+
]=]

0 commit comments

Comments
 (0)