From 81a7b57d2717a5463814a245b6c2aecca2c8cb58 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Sat, 16 Nov 2024 17:12:01 -0300 Subject: [PATCH] fix: don't ICE when declaring an invalid union in a function arg in a field Fixes #845. --- spec/lang/declaration/union_spec.lua | 16 ++++++++++++++++ tl.lua | 8 +++++--- tl.tl | 8 +++++--- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/spec/lang/declaration/union_spec.lua b/spec/lang/declaration/union_spec.lua index 43cc9c69d..d8ce7a044 100644 --- a/spec/lang/declaration/union_spec.lua +++ b/spec/lang/declaration/union_spec.lua @@ -125,6 +125,22 @@ describe("union declaration", function() { y = 9, msg = "cannot discriminate a union between multiple table types" }, })) + it("cannot declare a union between multiple records in a function in a field (#845)", util.check_type_error([[ + local record A + a: T + end + + local record B + b: T + end + + local record C + f: function(A | B) + end + ]], { + { y = 10, msg = "cannot discriminate a union between multiple table types" }, + })) + it("cannot declare a union between multiple function types", util.check_type_error([[ local t: function():(number) | function():(string) ]], { diff --git a/tl.lua b/tl.lua index abb36214b..0a42c65de 100644 --- a/tl.lua +++ b/tl.lua @@ -7301,9 +7301,11 @@ do end fresh_typevar_ctr = fresh_typevar_ctr + 1 - local ok - ok, t = typevar_resolver(nil, t, fresh_typevar, fresh_typearg) - assert(ok and t, "Internal Compiler Error: error creating fresh type variables") + local ok, errs + ok, t, errs = typevar_resolver(nil, t, fresh_typevar, fresh_typearg) + if not ok then + self.errs:collect(errs) + end return t end diff --git a/tl.tl b/tl.tl index 8b03c9d44..d3671b30f 100644 --- a/tl.tl +++ b/tl.tl @@ -7301,9 +7301,11 @@ do end fresh_typevar_ctr = fresh_typevar_ctr + 1 - local ok: boolean - ok, t = typevar_resolver(nil, t, fresh_typevar, fresh_typearg) - assert(ok and t, "Internal Compiler Error: error creating fresh type variables") + local ok, errs: boolean, {Error} + ok, t, errs = typevar_resolver(nil, t, fresh_typevar, fresh_typearg) + if not ok then + self.errs:collect(errs) + end return t end