Skip to content

Commit

Permalink
fix: don't crash on for given next and an unknown variable
Browse files Browse the repository at this point in the history
Fixes #897.
  • Loading branch information
hishamhm committed Jan 8, 2025
1 parent 365fbd3 commit 78c7fbb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
8 changes: 8 additions & 0 deletions spec/lang/statement/forin_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,12 @@ describe("forin", function()
{ msg = "v" },
}))
end)

it("does not crash given next and an unknown variable (#879)", util.check_type_error([[
for k, v in next, t, nil do
end
]], {
{ msg = "cannot resolve polymorphic function given arguments" },
{ msg = "unknown variable: t" },
}))
end)
9 changes: 7 additions & 2 deletions tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11935,8 +11935,13 @@ self:expand_type(node, values, elements) })
local exp1type = self:resolve_for_call(exptypes[1], args, false)

if exp1type.typename == "poly" then
local _
_, exp1type = self:type_check_function_call(exp1, exp1type, args, 0, exp1, { node.exps[2], node.exps[3] })
local _r, f
_r, f = self:type_check_function_call(exp1, exp1type, args, 0, exp1, { node.exps[2], node.exps[3] })
if f then
exp1type = f
else
self.errs:add(exp1, "cannot resolve polymorphic function given arguments")
end
end

if exp1type.typename == "function" then
Expand Down
9 changes: 7 additions & 2 deletions tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -11935,8 +11935,13 @@ do
local exp1type = self:resolve_for_call(exptypes[1], args, false)

if exp1type is PolyType then
local _: Type
_, exp1type = self:type_check_function_call(exp1, exp1type, args, 0, exp1, {node.exps[2], node.exps[3]})
local _r, f: Type, Type
_r, f = self:type_check_function_call(exp1, exp1type, args, 0, exp1, {node.exps[2], node.exps[3]})
if f then
exp1type = f
else
self.errs:add(exp1, "cannot resolve polymorphic function given arguments")
end
end

if exp1type is FunctionType then
Expand Down

0 comments on commit 78c7fbb

Please sign in to comment.