tl icon indicating copy to clipboard operation
tl copied to clipboard

Nested record metatable issue?

Open mtdowling opened this issue 1 year ago • 1 comments

It looks like there's an inconsistency with how nested record metatables are handled (or maybe I got something wrong).

This works:

local record Outer
    metamethod __call: function(container: Outer, instance: Outer): Outer
end

setmetatable(Outer, {
    __call = function(container: Outer, instance: Outer): Outer
        return setmetatable(instance, {__index = container})
    end
})

This doesn't work:

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
})

The second example fails with:

argument 2: type parameter <A>: got Wrapper.Inner, expected record ()

mtdowling avatar Aug 02 '24 04:08 mtdowling

Thank you for the report! I'll look into it.

hishamhm avatar Aug 02 '24 05:08 hishamhm

@mtdowling Thank you for the report! Should be fixed now in master.

hishamhm avatar Oct 13 '24 05:10 hishamhm