Skip to content

Commit

Permalink
fix: don't ICE when declaring an invalid union in a function arg in a…
Browse files Browse the repository at this point in the history
… field (#856)

Fixes #845.
  • Loading branch information
hishamhm authored Nov 16, 2024
1 parent 4bf78ea commit 7e1bc90
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
16 changes: 16 additions & 0 deletions spec/lang/declaration/union_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>
a: T
end
local record B<T>
b: T
end
local record C<T>
f: function<T>(A<T> | B<T>)
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)
]], {
Expand Down
8 changes: 5 additions & 3 deletions tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7e1bc90

Please sign in to comment.