From bce88456e9e893e7258f418a3d7c2b4d129eb66d Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 19 Jul 2024 14:44:27 -0300 Subject: [PATCH] fix: do not crash when comparing type defined with 'function' Using the plain 'function' type needs to define 'min_arity'. --- spec/assignment/to_function_spec.lua | 12 ++++++++++++ tl.lua | 2 ++ tl.tl | 2 ++ 3 files changed, 16 insertions(+) create mode 100644 spec/assignment/to_function_spec.lua diff --git a/spec/assignment/to_function_spec.lua b/spec/assignment/to_function_spec.lua new file mode 100644 index 000000000..57c35d5af --- /dev/null +++ b/spec/assignment/to_function_spec.lua @@ -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) diff --git a/tl.lua b/tl.lua index e6fdfad49..558be5f49 100644 --- a/tl.lua +++ b/tl.lua @@ -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 diff --git a/tl.tl b/tl.tl index f949fcaca..af1c8ccc9 100644 --- a/tl.tl +++ b/tl.tl @@ -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