summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-06-22 19:12:45 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-06-22 19:12:45 +0800
commit9091e064ab23b6b158551a4d256b65b033cb1688 (patch)
treecccfe054421dee937fb46390c70ba48869e5d7a1
parent79f76ed6611701ca5994fe110eb09e9309499918 (diff)
downloadlua-language-server-9091e064ab23b6b158551a4d256b65b033cb1688.zip
stash
-rw-r--r--changelog.md6
-rw-r--r--script/core/hover/table.lua2
-rw-r--r--script/parser/luadoc.lua1
-rw-r--r--script/vm/type.lua13
4 files changed, 16 insertions, 6 deletions
diff --git a/changelog.md b/changelog.md
index f0a43feb..8777103f 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,6 +1,12 @@
# changelog
## 3.4.0
+* `NEW` diagnostics:
+ * `cast-local-type`
+ * `assign-type-mismatch`
+ * `param-type-mismatch`
+ * `unknown-cast-variable`
+ * `cast-type-mismatch`
* `CHG` infer `nil` as redundant return value
```lua
local function f() end
diff --git a/script/core/hover/table.lua b/script/core/hover/table.lua
index a80051b9..3a2b7c77 100644
--- a/script/core/hover/table.lua
+++ b/script/core/hover/table.lua
@@ -180,7 +180,7 @@ return function (source)
for view in vm.getInfer(source):eachView(uri) do
if view == 'string'
- or vm.isSubType(uri, view, 'string') then
+ or (view ~= 'unknown' and view ~= 'any' and vm.isSubType(uri, view, 'string')) then
return nil
end
end
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index c4f40ac4..94be437f 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -69,6 +69,7 @@ Symbol <- ({} {
ev = '\v',
name = (m.R('az', 'AZ', '09', '\x80\xff') + m.S('_')) * (m.R('az', 'AZ', '__', '09', '\x80\xff') + m.S('_.*-'))^0,
Char10 = function (char)
+ ---@type integer?
char = tonumber(char)
if not char or char < 0 or char > 255 then
return ''
diff --git a/script/vm/type.lua b/script/vm/type.lua
index 208f21ed..1cbda65d 100644
--- a/script/vm/type.lua
+++ b/script/vm/type.lua
@@ -87,7 +87,9 @@ function vm.isSubType(uri, child, parent, mark)
local childName = getNodeName(child)
local parentName = getNodeName(parent)
if childName == 'any'
- or parentName == 'any' then
+ or parentName == 'any'
+ or childName == 'unknown'
+ or parentName == 'unknown' then
return true
end
@@ -240,12 +242,13 @@ function vm.canCastType(uri, defNode, refNode)
local defInfer = vm.getInfer(defNode)
local refInfer = vm.getInfer(refNode)
- if defInfer:hasUnknown(uri)
- or defInfer:hasAny(uri) then
+ if defInfer:hasAny(uri) then
return true
end
- if refInfer:hasUnknown(uri)
- or refInfer:hasAny(uri) then
+ if refInfer:hasAny(uri) then
+ return true
+ end
+ if defInfer:view(uri) == 'unknown' then
return true
end