Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Self parametric type bug? #877

Closed
mtdowling opened this issue Dec 18, 2024 · 1 comment
Closed

Self parametric type bug? #877

mtdowling opened this issue Dec 18, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@mtdowling
Copy link

Using a self parametric type with an interface seems to somehow inherit the record context from which a generic method is called.

-- Define an interface that uses self.
-- Using self should automatically refine implementations to map self to the impl.
local interface Container
    new: function(): self
end

-- Calling Foo.new should return a Foo (that is, replace `self` with `Foo`)
local record Foo is Container end

-- Use another collaborating record to demonstrate the bug.
local record SomeRecord
    update: function(self: SomeRecord)
end

local function foo<C is Container>(c: C)
end

-- Calling foo, which expects a Container, from this outer scope works.
local outerValue = Foo.new()
foo(outerValue) -- works!

-- Calling foo from within SomeRecord.update does not work.
function SomeRecord:update()
    local value = Foo.new()
    foo(value) -- Doesn't work?
    --  ^ given type SomeRecord does not satisfy Container constraint in type variable C
end
@hishamhm hishamhm added the bug Something isn't working label Dec 18, 2024
@hishamhm
Copy link
Member

hishamhm commented Jan 8, 2025

Thank you for reporting!

This one took a while to fix. Commit 365fbd3 should do it, at least for cases without generics. There is a pending test
showcasing the cases which are not covered by this commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants