Skip to content

Commit 36ed61d

Browse files
committed
fix #1871
1 parent e28d88a commit 36ed61d

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

changelog.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
* `FIX` [#1864]
55
* `FIX` [#1868]
66
* `FIX` [#1869]
7+
* `FIX` [#1871]
78

89
[#1864]: https://github.com./sumneko/lua-language-server/issues/1864
910
[#1868]: https://github.com./sumneko/lua-language-server/issues/1868
1011
[#1869]: https://github.com./sumneko/lua-language-server/issues/1869
12+
[#1871]: https://github.com./sumneko/lua-language-server/issues/1871
1113

1214
## 3.6.8
1315
`2023-1-31`

script/vm/compiler.lua

+5-5
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,11 @@ local searchFieldSwitch = util.switch()
192192
or not math.tointeger(key) then
193193
return
194194
end
195-
pushResult(source.node)
195+
pushResult(source.node, true)
196196
end
197197
if type(key) == 'table' then
198198
if vm.isSubType(suri, key, 'integer') then
199-
pushResult(source.node)
199+
pushResult(source.node, true)
200200
end
201201
end
202202
end)
@@ -217,21 +217,21 @@ local searchFieldSwitch = util.switch()
217217
or (fn.name == 'number' and type(key) == 'number')
218218
or (fn.name == 'integer' and math.tointeger(key))
219219
or (fn.name == 'string' and type(key) == 'string') then
220-
pushResult(field)
220+
pushResult(field, true)
221221
end
222222
elseif fn.type == 'doc.type.string'
223223
or fn.type == 'doc.type.integer'
224224
or fn.type == 'doc.type.boolean' then
225225
if key == vm.ANY
226226
or fn[1] == key then
227-
pushResult(field)
227+
pushResult(field, true)
228228
end
229229
end
230230
end
231231
end
232232
if fieldKey.type == 'doc.field.name' then
233233
if key == vm.ANY or fieldKey[1] == key then
234-
pushResult(field)
234+
pushResult(field, true)
235235
end
236236
end
237237
end

test/diagnostics/type-check.lua

+11
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,17 @@ end
11901190
print(is_string(3))
11911191
]]
11921192

1193+
TEST [[
1194+
---@class SomeClass
1195+
---@field [1] string
1196+
-- ...
1197+
1198+
---@param some_param SomeClass|SomeClass[]
1199+
local function some_fn(some_param) return end
1200+
1201+
some_fn { { "test" } } -- <- diagnostic: "Cannot assign `table` to `string`."
1202+
]]
1203+
11931204
config.remove(nil, 'Lua.diagnostics.disable', 'unused-local')
11941205
config.remove(nil, 'Lua.diagnostics.disable', 'unused-function')
11951206
config.remove(nil, 'Lua.diagnostics.disable', 'undefined-global')

0 commit comments

Comments
 (0)