-
-
Notifications
You must be signed in to change notification settings - Fork 319
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
check that the shape of the table corresponds to the class #2768
Conversation
it does not support classes in this form: ---@class SomeClass
---@field [1] string and array |
script/vm/type.lua
Outdated
@@ -328,7 +328,7 @@ function vm.isSubType(uri, child, parent, mark, errs) | |||
for n in child:eachObject() do | |||
local nodeName = vm.getNodeName(n) | |||
if nodeName | |||
and not (nodeName == 'nil' and weakNil) | |||
and not (nodeName == 'nil' and weakNil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary space
script/vm/type.lua
Outdated
|
||
for i, field in ipairs(set) do | ||
local key = vm.getKeyName(field) | ||
local node = vm.compileNode(field) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad indent
script/vm/type.lua
Outdated
@@ -753,7 +796,7 @@ function vm.viewTypeErrorMessage(uri, errs) | |||
lparams[paramName] = vm.viewKey(value, uri) | |||
else | |||
lparams[paramName] = vm.getInfer(value):view(uri) | |||
or vm.getInfer(value):view(uri) | |||
or vm.getInfer(value):view(uri) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
donot change here
script/vm/type.lua
Outdated
end | ||
end | ||
|
||
------------------------------- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
donot add dashes
I thought this was the intended behavior, and a large part of the reason why |
ee7c3ef
to
6cd1038
Compare
I think you might need to change the example in your comment: ----@class Foo
+---@class (exact) Foo
---@field FooField integer
---@field afield? string
---@param FooParam Foo
local function test(FooParam) end
|
I think this check is too strict after testing it with real projects. I will set an option for it and keep it off by default. |
It was released yesterday, but was toggled off by default. The example in the pull request works nicely. - pull request - LuaLS/lua-language-server#2768 - comment saying why it was toggled off - LuaLS/lua-language-server#2768 (comment) - changelog with a little more info - https://github.com/LuaLS/lua-language-server/blob/d702a55715df19a219e963da496e6fb76db0aacd/changelog.md?plain=1#L8
It was released yesterday, but was toggled off by default. The example in the pull request works nicely. - pull request - LuaLS/lua-language-server#2768 - comment saying why it was toggled off - LuaLS/lua-language-server#2768 (comment) - changelog with a little more info - https://github.com/LuaLS/lua-language-server/blob/d702a55715df19a219e963da496e6fb76db0aacd/changelog.md?plain=1#L8
Perhaps it could be enabled by default on |
@sumneko Can you give examples where it seems too strict? I haven't looked at the change extensively, but my gut reaction is that the class definitions would be improper if this isn't passing. |
Hi,
this PR add a correspondence check between the table and the class.
related to the problem #2734.
demonstration:
this reinforces the param-type-mismatch diagnosis, if the parameter is a table, it will need to correspond to the signature of the function.
this PR can still be greatly improved and does not pass all tests