diff --git a/spec/lang/stdlib/setmetatable_spec.lua b/spec/lang/stdlib/setmetatable_spec.lua index 611303696..67bdf0827 100644 --- a/spec/lang/stdlib/setmetatable_spec.lua +++ b/spec/lang/stdlib/setmetatable_spec.lua @@ -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) diff --git a/tl.lua b/tl.lua index ec9cc491d..0ed516366 100644 --- a/tl.lua +++ b/tl.lua @@ -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, diff --git a/tl.tl b/tl.tl index ae9583f95..023927497 100644 --- a/tl.tl +++ b/tl.tl @@ -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,