Skip to content

Commit

Permalink
fix regression in generic records with __call
Browse files Browse the repository at this point in the history
Thanks @mtdowling for the report!

Fixes #901.
  • Loading branch information
hishamhm committed Jan 11, 2025
1 parent 00069a5 commit 39d06ba
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
46 changes: 46 additions & 0 deletions spec/lang/metamethods/call_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,50 @@ describe("metamethod __call", function()
f()
]]))

describe("regression tests for #901", function()
it("case 1", util.check([[
local record Foo<S>
value: S
metamethod __call: function(self: Foo<S>, value: S): Foo<S>
end
Foo(1)
]]))

it("case 2", util.check([[
local record someModule
record Foo<S>
value: S
metamethod __call: function(self: Foo<S>, value: S): Foo<S>
end
end
someModule.Foo(1)
]]))

it("case 3", util.check([[
local record Foo<S>
value: S
metamethod __call: function(self: Foo<S>, value: S): Foo<S>
end
Foo(1)
]]))

it("case 4", util.check([[
local record Foo<S>
value: S
metamethod __call: function(self: Foo<S>, value: S): Foo<S>
end
local mt: metatable<Foo> = {
__call = function<S>(self: Foo<S>, value: S): Foo<S>
return setmetatable({}, {__index = Foo})
end
}
setmetatable(Foo, mt)
Foo(1)
]]))
end)
end)
5 changes: 1 addition & 4 deletions tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9524,10 +9524,7 @@ a.types[i], b.types[i]), }
end

if func.typename == "typedecl" then
local funcdef = func.def
if funcdef.typename == "record" then
func = func.def
end
return self:resolve_for_call(func.def, args, is_method)
end

if func.fields and func.meta_fields and func.meta_fields["__call"] then
Expand Down
5 changes: 1 addition & 4 deletions tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -9524,10 +9524,7 @@ do
end
-- resolve if prototype
if func is TypeDeclType then
local funcdef = func.def
if funcdef is RecordType then
func = func.def
end
return self:resolve_for_call(func.def, args, is_method)
end
-- resolve if metatable
if func is RecordLikeType and func.meta_fields and func.meta_fields["__call"] then
Expand Down

0 comments on commit 39d06ba

Please sign in to comment.