diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-06-23 02:05:01 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-06-23 02:05:01 +0800 |
commit | c2fb1d5e889510f8175c25277587e7ea91fb2170 (patch) | |
tree | 1ad171838794694a7d4c64987088578c70f57b26 | |
parent | 830165b6025107188e564fc4590e5eb633e1a13d (diff) | |
download | lua-language-server-c2fb1d5e889510f8175c25277587e7ea91fb2170.zip |
fix #1228 `doc.as` may not work
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | script/vm/compiler.lua | 13 | ||||
-rw-r--r-- | test/type_inference/init.lua | 6 |
3 files changed, 14 insertions, 6 deletions
diff --git a/changelog.md b/changelog.md index 8777103f..2476c817 100644 --- a/changelog.md +++ b/changelog.md @@ -23,6 +23,7 @@ local n2 = f(0) -- `n2` is `number` local n3 = f(0, 0) -- `n3` is `string` ``` +* `FIX` [#1228](https://github.com/sumneko/lua-language-server/issues/1228) ## 3.3.1 `2022-6-17` diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 2f3cc36f..5ebf624c 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -629,7 +629,7 @@ local function bindAs(source) local root = guide.getRoot(source) local docs = root.docs if not docs then - return + return false end local ases = docs._asCache if not ases then @@ -645,19 +645,20 @@ local function bindAs(source) end) end + if #ases == 0 then + return false + end + local max = #ases local index local left = 1 local right = max for _ = 1, 1000 do - index = left + (right - left) // 2 - if index <= left then + if left == right then index = left break - elseif index >= right then - index = right - break end + index = left + (right - left) // 2 local doc = ases[index] if doc.originalComment.start < source.finish + 2 then left = index + 1 diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index bc497f37..33184569 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -2998,3 +2998,9 @@ local t local <?n?> = t[i] ]] + +TEST 'string' [=[ +local x = true +local y = x--[[@as integer]] --is `integer` here +local z = <?x?>--[[@as string]] --is `true` here +]=] |