diff options
-rw-r--r-- | script/core/diagnostics/param-type-mismatch.lua | 3 | ||||
-rw-r--r-- | script/core/diagnostics/unused-vararg.lua | 3 | ||||
-rw-r--r-- | script/vm/runner.lua | 2 | ||||
-rw-r--r-- | test/diagnostics/type-check.lua | 8 | ||||
-rw-r--r-- | test/type_inference/init.lua | 16 |
5 files changed, 31 insertions, 1 deletions
diff --git a/script/core/diagnostics/param-type-mismatch.lua b/script/core/diagnostics/param-type-mismatch.lua index a4390b50..6f34f579 100644 --- a/script/core/diagnostics/param-type-mismatch.lua +++ b/script/core/diagnostics/param-type-mismatch.lua @@ -22,6 +22,9 @@ return function (uri, callback) local param = f.args and f.args[i] if param then defNode:merge(vm.compileNode(param)) + if param[1] == '...' then + defNode:addOptional() + end end end end diff --git a/script/core/diagnostics/unused-vararg.lua b/script/core/diagnostics/unused-vararg.lua index ce033cf3..08f12c4d 100644 --- a/script/core/diagnostics/unused-vararg.lua +++ b/script/core/diagnostics/unused-vararg.lua @@ -15,6 +15,9 @@ return function (uri, callback) end guide.eachSourceType(ast.ast, 'function', function (source) + if #source == 0 then + return + end local args = source.args if not args then return diff --git a/script/vm/runner.lua b/script/vm/runner.lua index 8c1e816e..fcd0f681 100644 --- a/script/vm/runner.lua +++ b/script/vm/runner.lua @@ -209,7 +209,7 @@ function mt:_lookInto(action, topNode, outNode) local topNode1, outNode1 = self:_lookInto(action[1], topNode, outNode) local topNode2, outNode2 = self:_lookInto(action[2], outNode1, outNode1:copy()) topNode = vm.createNode(topNode1, topNode2) - outNode = outNode2 + outNode = outNode2:copy() elseif action.op.type == '==' or action.op.type == '~=' then local exp, checker diff --git a/test/diagnostics/type-check.lua b/test/diagnostics/type-check.lua index b00e1ba0..e79c767d 100644 --- a/test/diagnostics/type-check.lua +++ b/test/diagnostics/type-check.lua @@ -580,5 +580,13 @@ function F() end ]] +TEST [[ +---@param ... number +local function f(...) +end + +f(nil) +]] + config.remove(nil, 'Lua.diagnostics.disable', 'unused-local') config.remove(nil, 'Lua.diagnostics.disable', 'undefined-global') diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index d56761c5..3cf381d1 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -3184,3 +3184,19 @@ local t = { x = n and <?n?>, } ]] + +TEST 'table' [[ +---@type table? +local n + +if not n or not <?n?>.x then +end +]] + +TEST 'table' [[ +---@type table? +local n + +if not n or not <?n?>[1] then +end +]] |