Skip to content

Commit

Permalink
fix #1317
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Jul 11, 2022
1 parent db71c1e commit 492ed7f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* `FIX` [#1284](https://github.com/sumneko/lua-language-server/issues/1284)
* `FIX` [#1292](https://github.com/sumneko/lua-language-server/issues/1292)
* `FIX` [#1294](https://github.com/sumneko/lua-language-server/issues/1294)
* `FIX` [#1317](https://github.com/sumneko/lua-language-server/issues/1317)

## 3.4.2
`2022-7-6`
Expand Down
30 changes: 16 additions & 14 deletions script/parser/compile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ local uchar = utf8.char
local tconcat = table.concat
local tinsert = table.insert
local tointeger = math.tointeger
local mtype = math.type
local tonumber = tonumber
local maxinteger = math.maxinteger
local assert = assert
local next = next

_ENV = nil

Expand Down Expand Up @@ -2669,7 +2667,6 @@ local function parseVarTails(parser, isLocal)
end
if isLocal then
createLocal(second, parseLocalAttrs())
second.effect = maxinteger
end
skipSpace()
if Tokens[Index + 1] ~= ',' then
Expand All @@ -2684,7 +2681,6 @@ local function parseVarTails(parser, isLocal)
end
if isLocal then
createLocal(third, parseLocalAttrs())
third.effect = maxinteger
end
local rest = { third }
while true do
Expand All @@ -2701,15 +2697,13 @@ local function parseVarTails(parser, isLocal)
end
if isLocal then
createLocal(name, parseLocalAttrs())
name.effect = maxinteger
end
rest[#rest+1] = name
end
end

local function bindValue(n, v, index, lastValue, isLocal, isSet)
if isLocal then
n.effect = lastRightPosition()
if v and v.special then
addSpecial(v.special, n)
end
Expand Down Expand Up @@ -2755,9 +2749,6 @@ local function bindValue(n, v, index, lastValue, isLocal, isSet)
n.value = v
n.range = v.finish
v.parent = n
if isLocal then
n.effect = lastRightPosition()
end
end
end

Expand All @@ -2777,13 +2768,15 @@ local function parseMultiVars(n1, parser, isLocal)
local index = 1
bindValue(n1, v1, index, nil, isLocal, isSet)
local lastValue = v1
local lastVar = n1
if n2 then
max = 2
if not v2 then
index = 2
end
bindValue(n2, v2, index, lastValue, isLocal, isSet)
lastValue = v2 or lastValue
lastVar = n2
pushActionIntoCurrentChunk(n2)
end
if nrest then
Expand All @@ -2796,10 +2789,24 @@ local function parseMultiVars(n1, parser, isLocal)
end
bindValue(n, v, index, lastValue, isLocal, isSet)
lastValue = v or lastValue
lastVar = n
pushActionIntoCurrentChunk(n)
end
end

if isLocal then
local effect = lastValue and lastValue.finish or lastVar.finish
n1.effect = effect
if n2 then
n2.effect = effect
end
if nrest then
for i = 1, #nrest do
nrest[i].effect = effect
end
end
end

if v2 and not n2 then
v2.redundant = {
max = max,
Expand Down Expand Up @@ -2921,11 +2928,6 @@ local function parseLocal()
pushActionIntoCurrentChunk(loc)
skipSpace()
parseMultiVars(loc, parseName, true)
if loc.value then
loc.effect = loc.value.finish
else
loc.effect = loc.finish
end

return loc
end
Expand Down
6 changes: 6 additions & 0 deletions test/diagnostics/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,12 @@ TEST [[
---@cast <!x!> integer
]]

TEST [[
---@diagnostic disable: unused-local
local x, y
---@cast y number
]]

TEST [[
---@class A
Expand Down

0 comments on commit 492ed7f

Please sign in to comment.