Skip to content

Commit 349237e

Browse files
committed
remove optionals for all vars of for .. in
1 parent 46910e4 commit 349237e

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

script/vm/compiler.lua

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -911,12 +911,8 @@ local function compileForVars(source)
911911
if source.keys then
912912
for i, loc in ipairs(source.keys) do
913913
local node = getReturn(source._iterator, i, source._iterArgs)
914-
if node then
915-
if i == 1 then
916-
node:removeOptional()
917-
end
918-
source._iterVars[loc] = node
919-
end
914+
node:removeOptional()
915+
source._iterVars[loc] = node
920916
end
921917
end
922918
end

test/type_inference/init.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3234,3 +3234,19 @@ local <?x?> = f()
32343234
TEST 'number' [=[
32353235
local <?x?> = X --[[@as number]]
32363236
]=]
3237+
3238+
TEST 'number' [[
3239+
---@return number?, number?
3240+
local function f() end
3241+
3242+
for <?x?>, y in f do
3243+
end
3244+
]]
3245+
3246+
TEST 'number' [[
3247+
---@return number?, number?
3248+
local function f() end
3249+
3250+
for x, <?y?> in f do
3251+
end
3252+
]]

0 commit comments

Comments
 (0)