Skip to content

Commit

Permalink
fix: do not crash when comparing type defined with 'function'
Browse files Browse the repository at this point in the history
Using the plain 'function' type needs to define 'min_arity'.
  • Loading branch information
hishamhm committed Jul 19, 2024
1 parent 6485d89 commit bce8845
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions spec/assignment/to_function_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
local util = require("spec.util")

describe("assignment to function", function()
it("does not crash when using plain function definitions", util.check([[
local my_load: function(string, ? string, ? string, ? table): (function, string)
local function run_file()
local chunk: function(any):(any)
chunk = my_load("")
end
]]))
end)
2 changes: 2 additions & 0 deletions tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2577,6 +2577,8 @@ do
else
typ.args = new_tuple(ps, i, { new_type(ps, i, "any") }, true)
typ.rets = new_tuple(ps, i, { new_type(ps, i, "any") }, true)
typ.is_method = false
typ.min_arity = 0
end
return i, typ
end
Expand Down
2 changes: 2 additions & 0 deletions tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -2577,6 +2577,8 @@ local function parse_function_type(ps: ParseState, i: integer): integer, Functio
else
typ.args = new_tuple(ps, i, { new_type(ps, i, "any") }, true)
typ.rets = new_tuple(ps, i, { new_type(ps, i, "any") }, true)
typ.is_method = false
typ.min_arity = 0
end
return i, typ
end
Expand Down

0 comments on commit bce8845

Please sign in to comment.