Skip to content

Commit

Permalink
fix incorrect param-type-mismatch diagnostic for optional fields
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Dec 6, 2024
1 parent 4411cdb commit 31c83e0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<!-- Add all new changes here. They will be moved under a version at release -->
* `CHG` Update Love2d version
* `CHG` Improve type infer of `table.unpack` and `unpack`
* `FIX` missing-fields diagnostic now warns about missing inherited fields
* `FIX` `missing-fields` diagnostic now warns about missing inherited fields
* `FIX` Incorrect `param-type-mismatch` diagnostic for optional fields

## 3.13.2
`2024-11-21`
Expand Down
4 changes: 4 additions & 0 deletions script/vm/type.lua
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ local function checkValue(parent, child, mark, errs)
local knode = vm.compileNode(pfield.name)
local cvalues = vm.getTableValue(uri, tnode, knode, true)
if not cvalues then
if pfield.optional then
goto continue
end
if errs then
errs[#errs+1] = 'TYPE_ERROR_TABLE_NO_FIELD'
errs[#errs+1] = pfield.name
Expand All @@ -260,6 +263,7 @@ local function checkValue(parent, child, mark, errs)
end
return false
end
::continue::
end
end
return true
Expand Down
10 changes: 10 additions & 0 deletions test/diagnostics/param-type-mismatch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,14 @@ local k = t[i].int
f(k)
]]

TEST [[
---@type [1, 2, 3]
local x
---@param y { [1]?: 1, [2]?: 2, [3]?: 3, [4]?: 4}
local function f(y) end
f(x)
]]

config.set(nil, 'Lua.type.checkTableShape', false)

0 comments on commit 31c83e0

Please sign in to comment.