Skip to content

Commit

Permalink
Merge pull request #2970 from estebanfer/fix-missing-fields-inherited…
Browse files Browse the repository at this point in the history
…-fields

Fix missing-fields diagnostic not warning about missing inherited fields
  • Loading branch information
sumneko authored Dec 6, 2024
2 parents 2d4176f + bc486b9 commit 7b2d585
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 4 deletions.
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Unreleased
<!-- Add all new changes here. They will be moved under a version at release -->
`2024-11-26`
* `FIX` missing-fields diagnostic now warns about missing inherited fields
* `CHG` Update Love2d version

## 3.13.2
Expand Down
5 changes: 3 additions & 2 deletions script/core/diagnostics/missing-fields.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ return function (uri, callback)
for className, samedefs in pairs(sortedDefs) do
local missedKeys = {}
for _, def in ipairs(samedefs) do
if not def.fields or #def.fields == 0 then
local fields = vm.getFields(def)
if #fields == 0 then
goto continue
end

Expand All @@ -55,7 +56,7 @@ return function (uri, callback)
end
end

for _, field in ipairs(def.fields) do
for _, field in ipairs(fields) do
if not field.optional
and not vm.compileNode(field):isNullable() then
local key = vm.getKeyName(field)
Expand Down
112 changes: 111 additions & 1 deletion test/diagnostics/missing-fields.lua
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,114 @@ TEST[[
---@type A
local t = <!{x = 1}!>
]]
]]

-- Inheritance

TEST[[
---@class A
---@field x number
---@class B: A
---@type B
local t = <!{}!>
]]

TEST[[
---@class A
---@field x number
---@field y number
---@class B: A
---@type B
local t = <!{y = 1}!>
]]

TEST[[
---@class A
---@field x number
---@class B: A
---@field y number
---@type B
local t = <!{y = 1}!>
]]

-- Inheritance + optional

TEST[[
---@class A
---@field x? number
---@class B: A
---@type B
local t = {}
]]

TEST[[
---@class A
---@field x? number
---@field y number
---@class B: A
---@type B
local t = {y = 1}
]]

TEST[[
---@class A
---@field x? number
---@class B: A
---@field y number
---@type B
local t = {y = 1}
]]

-- Inheritance + function call

TEST[[
---@class A
---@field x number
---@class B: A
---@param b B
local function f(b) end
f <!{}!>
]]

TEST[[
---@class A
---@field x number
---@field y number
---@class B: A
---@param b B
local function f(b) end
f <!{y = 1}!>
]]

TEST[[
---@class A
---@field x number
---@class B: A
---@field y number
---@param b B
local function f(b) end
f <!{y = 1}!>
]]

--

0 comments on commit 7b2d585

Please sign in to comment.