diff --git a/spec/lang/declaration/union_spec.lua b/spec/lang/declaration/union_spec.lua index 43cc9c69..d8ce7a04 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 abb36214..0a42c65d 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 8b03c9d4..d3671b30 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