diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-06-29 16:09:47 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-06-29 16:09:47 +0800 |
commit | 349237eb93facad91ca7389c56de9bb30f60066b (patch) | |
tree | 3622bd215b5253b9c8413288bc6269f190d40299 | |
parent | 46910e464bfab9992895898b4c1795e494796e39 (diff) | |
download | lua-language-server-349237eb93facad91ca7389c56de9bb30f60066b.zip |
remove optionals for all vars of `for .. in`
-rw-r--r-- | script/vm/compiler.lua | 8 | ||||
-rw-r--r-- | test/type_inference/init.lua | 16 |
2 files changed, 18 insertions, 6 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 5a306308..1abad3e3 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -911,12 +911,8 @@ local function compileForVars(source) if source.keys then for i, loc in ipairs(source.keys) do local node = getReturn(source._iterator, i, source._iterArgs) - if node then - if i == 1 then - node:removeOptional() - end - source._iterVars[loc] = node - end + node:removeOptional() + source._iterVars[loc] = node end end end diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index a6791e22..624cf4b9 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -3234,3 +3234,19 @@ local <?x?> = f() TEST 'number' [=[ local <?x?> = X --[[@as number]] ]=] + +TEST 'number' [[ +---@return number?, number? +local function f() end + +for <?x?>, y in f do +end +]] + +TEST 'number' [[ +---@return number?, number? +local function f() end + +for x, <?y?> in f do +end +]] |