summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/core/diagnostics/assign-type-mismatch.lua15
-rw-r--r--script/vm/compiler.lua12
-rw-r--r--test/hover/init.lua2
3 files changed, 15 insertions, 14 deletions
diff --git a/script/core/diagnostics/assign-type-mismatch.lua b/script/core/diagnostics/assign-type-mismatch.lua
index b7d11226..ae4b3512 100644
--- a/script/core/diagnostics/assign-type-mismatch.lua
+++ b/script/core/diagnostics/assign-type-mismatch.lua
@@ -38,13 +38,14 @@ return function (uri, callback)
end
end
local valueNode = vm.compileNode(value)
- if source.type == 'setindex'
- or source.type == 'setfield'
- or source.type == 'tablefield'
- or source.type == 'tableindex' then
- if valueNode:hasName 'nil' then
- valueNode = valueNode:copy():removeOptional()
- if valueNode:isEmpty() then
+ if source.type == 'setindex'
+ and vm.isSubType(uri, valueNode, 'nil') then
+ -- boolean[1] = nil
+ local tnode = vm.compileNode(source.node)
+ for n in tnode:eachObject() do
+ if n.type == 'doc.type.array'
+ or n.type == 'doc.type.table'
+ or n.type == 'table' then
return
end
end
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 70a4ea92..e3c08cb9 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -1388,7 +1388,7 @@ local compilerSwitch = util.switch()
local uri = guide.getUri(source)
local value = vm.getTableValue(uri, vm.compileNode(source.node), key)
if value then
- vm.setNode(source, value):removeOptional()
+ vm.setNode(source, value)
end
for k in key:eachObject() do
if k.type == 'global' and k.cate == 'type' then
@@ -1396,7 +1396,7 @@ local compilerSwitch = util.switch()
vm.compileByParentNode(source.node, k, false, function (src)
vm.setNode(source, vm.compileNode(src))
if src.value then
- vm.setNode(source, vm.compileNode(src.value)):removeOptional()
+ vm.setNode(source, vm.compileNode(src.value))
end
end)
end
@@ -1406,7 +1406,7 @@ local compilerSwitch = util.switch()
vm.compileByParentNode(source.node, key, false, function (src)
vm.setNode(source, vm.compileNode(src))
if src.value then
- vm.setNode(source, vm.compileNode(src.value)):removeOptional()
+ vm.setNode(source, vm.compileNode(src.value))
end
end)
end
@@ -1420,7 +1420,7 @@ local compilerSwitch = util.switch()
vm.compileByParentNode(source.node, key, false, function (src)
if src.type == 'doc.type.field'
or src.type == 'doc.field' then
- vm.setNode(source, vm.compileNode(src)):removeOptional()
+ vm.setNode(source, vm.compileNode(src))
end
end)
end)
@@ -1450,13 +1450,13 @@ local compilerSwitch = util.switch()
if src.type == 'doc.field'
or src.type == 'doc.type.field' then
hasMarkDoc = true
- vm.setNode(source, vm.compileNode(src)):removeOptional()
+ vm.setNode(source, vm.compileNode(src))
end
end)
end
if not hasMarkDoc and source.value then
- vm.setNode(source, vm.compileNode(source.value)):removeOptional()
+ vm.setNode(source, vm.compileNode(source.value))
end
end)
diff --git a/test/hover/init.lua b/test/hover/init.lua
index 0ee62c1b..a97cf3ae 100644
--- a/test/hover/init.lua
+++ b/test/hover/init.lua
@@ -772,7 +772,7 @@ local <?t?> = {
]]
[[
local t: {
- f: file*,
+ f?: file*,
}
]]