teal-language / tl

The compiler for Teal, a typed dialect of Lua
MIT License
2.11k stars 109 forks source link

Nested record metatable issue? #772

Open mtdowling opened 1 month ago

mtdowling commented 1 month ago

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 ()
hishamhm commented 1 month ago

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