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

Exact classes can have fields injected when used as parameters to funcitons #2288

Open
GiuseppeIII opened this issue Aug 25, 2023 · 2 comments

Comments

@GiuseppeIII
Copy link

GiuseppeIII commented Aug 25, 2023

Love the new exact class! When using it though, I noticed that I could still 'inject' fields into an exact class when it is used as the input to a function. Example:

---@class (exact) TestClass
---@field public a number
---@field public b string
---@field public c boolean

---@param test_param TestClass
local function test(test_param)
end

test({a = 1, b = "2", c = true, d = 4})

causes no error.

I am not sure if this is intended or not, but I would expect to get an warning like: Fields cannot be injected into the reference of `TestClass` for `d`. To do so, use `---@class` for `test_param`.Lua Diagnostics.(inject-field) here.

@GiuseppeIII GiuseppeIII changed the title Can add a param to an exact class that is used as the input to a function Exact classes can have fields injected when used as parameters to funcitons Aug 25, 2023
@Alex-Muirhead
Copy link

Alex-Muirhead commented Sep 29, 2023

This doesn't appear to be limited to classes used as parameters, as the following also doesn't show any warnings.

---@class (exact) TestClass
---@field public a number
---@field public b string
---@field public c boolean

---@type TestClass
local test = {a = 1, b = "2", c = true, d = 4}

@nanaktaev
Copy link

It would be great to see warnings in such cases indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants