Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't ICE on invalid union in a function arg in a field #856

Merged
merged 1 commit into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading