Skip to content

Commit 599b447

Browse files
committed
fix #1242
wrong `sindex` in multi-assign which last exp is `call` or `varargs`
1 parent d5327b0 commit 599b447

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
* `FIX` sometimes workspace diagnostics are not triggered
4646
* `FIX` [#1228](https://github.com/sumneko/lua-language-server/issues/1228)
4747
* `FIX` [#1229](https://github.com/sumneko/lua-language-server/issues/1229)
48+
* `FIX` [#1242](https://github.com/sumneko/lua-language-server/issues/1242)
4849

4950
## 3.3.1
5051
`2022-6-17`

script/parser/compile.lua

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2767,11 +2767,15 @@ local function parseMultiVars(n1, parser, isLocal)
27672767
missExp()
27682768
end
27692769
end
2770-
bindValue(n1, v1, 1, nil, isLocal, isSet)
2770+
local index = 1
2771+
bindValue(n1, v1, index, nil, isLocal, isSet)
27712772
local lastValue = v1
27722773
if n2 then
27732774
max = 2
2774-
bindValue(n2, v2, 2, lastValue, isLocal, isSet)
2775+
if not v2 then
2776+
index = 2
2777+
end
2778+
bindValue(n2, v2, index, lastValue, isLocal, isSet)
27752779
lastValue = v2 or lastValue
27762780
pushActionIntoCurrentChunk(n2)
27772781
end
@@ -2780,7 +2784,10 @@ local function parseMultiVars(n1, parser, isLocal)
27802784
local n = nrest[i]
27812785
local v = vrest and vrest[i]
27822786
max = i + 2
2783-
bindValue(n, v, max, lastValue, isLocal, isSet)
2787+
if not v then
2788+
index = index + 1
2789+
end
2790+
bindValue(n, v, index, lastValue, isLocal, isSet)
27842791
lastValue = v or lastValue
27852792
pushActionIntoCurrentChunk(n)
27862793
end

test/type_inference/init.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3149,3 +3149,21 @@ TEST 'A' [[
31493149
---@type A
31503150
local <?s?> = ''
31513151
]]
3152+
3153+
TEST 'number' [[
3154+
---@return number
3155+
local function f() end
3156+
local x, <?y?> = 1, f()
3157+
]]
3158+
3159+
TEST 'boolean' [[
3160+
---@return number, boolean
3161+
local function f() end
3162+
local x, y, <?z?> = 1, f()
3163+
]]
3164+
3165+
TEST 'number' [[
3166+
---@return number, boolean
3167+
local function f() end
3168+
local x, y, <?z?> = 1, 2, f()
3169+
]]

0 commit comments

Comments
 (0)