Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing-fields diagnostic not warning about missing inherited fields #2970

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}!>
]]

--