Skip to content

Commit

Permalink
fix: resolve type parameter in setmetatable using nested records
Browse files Browse the repository at this point in the history
Fixes #772.
  • Loading branch information
hishamhm committed Oct 13, 2024
1 parent 1ed3598 commit ede28c9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions spec/lang/stdlib/setmetatable_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,18 @@ describe("setmetatable", function()
print(r("!!!", 1000)) -- prints 12000!!!
print((r + s).x) -- prints 32
]]))

it("works with nested records (regression test for #772", util.check([[
local record Wrapper
record Inner
metamethod __call: function(container: Inner, instance: Inner): Inner
end
end
setmetatable(Wrapper.Inner, {
__call = function(container: Wrapper.Inner, instance: Wrapper.Inner): Wrapper.Inner
return setmetatable(instance, {__index = container})
end
})
]]))
end)
4 changes: 4 additions & 0 deletions tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8590,6 +8590,10 @@ do
},
["nominal"] = {
["nominal"] = TypeChecker.are_same_nominals,
["typedecl"] = function(self, a, b)

return self:same_type(self:resolve_nominal(a), b.def)
end,
},
["record"] = {
["record"] = TypeChecker.eqtype_record,
Expand Down
4 changes: 4 additions & 0 deletions tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -8590,6 +8590,10 @@ do
},
["nominal"] = {
["nominal"] = TypeChecker.are_same_nominals,
["typedecl"] = function(self: TypeChecker, a: NominalType, b: TypeDeclType): boolean, {Error}
-- used when resolving type parameters
return self:same_type(self:resolve_nominal(a), b.def)
end,
},
["record"] = {
["record"] = TypeChecker.eqtype_record,
Expand Down

0 comments on commit ede28c9

Please sign in to comment.