Skip to content

Commit

Permalink
fix: regression in table generation for generic records
Browse files Browse the repository at this point in the history
Fixes #902
  • Loading branch information
hishamhm committed Jan 11, 2025
1 parent f3a23d5 commit 46e8b04
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
46 changes: 46 additions & 0 deletions spec/lang/code_gen/local_type_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,50 @@ describe("local type code generation", function()
{ y = 16, msg = "interfaces are abstract" },
}))

it("does not elide generic entries that are needed (#902)", util.gen([[
local record Qux<T>
v: integer
end
Qux.v = 123
local record Foo
record Bar<S>
value: S
metamethod __call: function(self, value: S): self
end
end
setmetatable(Foo.Bar, {
__call = function<S>(self, value: S): Foo.Bar<S>
return {value = value}
end
})
print(Foo.Bar("hi").value)
]], [[
local Qux = {}
Qux.v = 123
local Foo = {Bar = {}, }
setmetatable(Foo.Bar, {
__call = function(self, value)
return { value = value }
end,
})
print(Foo.Bar("hi").value)
]], nil, {}))

end)
3 changes: 3 additions & 0 deletions tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5237,6 +5237,9 @@ function tl.generate(ast, gen_target, opts)
for fname, ftype in fields_of(typ) do
if ftype.typename == "typedecl" then
local def = ftype.def
if def.typename == "generic" then
def = def.t
end
if def.typename == "record" then
if i > 0 then
table.insert(out, ",")
Expand Down
3 changes: 3 additions & 0 deletions tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -5237,6 +5237,9 @@ function tl.generate(ast: tl.Node, gen_target: GenTarget, opts?: GenerateOptions
for fname, ftype in fields_of(typ) do
if ftype is TypeDeclType then
local def = ftype.def
if def is GenericType then
def = def.t
end
if def is RecordType then
if i > 0 then
table.insert(out, ",")
Expand Down

0 comments on commit 46e8b04

Please sign in to comment.