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

New solver: explicitly typed table does not apply types onto function/method declarations #1516

Open
JohnnyMorganz opened this issue Nov 9, 2024 · 2 comments
Labels
bug Something isn't working new solver This issue is specific to the new solver.

Comments

@JohnnyMorganz
Copy link
Contributor

This definition works in the old solver, but fails in the new solver:

 type Class = {
    foo: (self: Class, bar: string) -> ()
}

local Impl = {} :: Class

function Impl:foo(bar)
    local p = self -- old solver: Class, new solver: unknown
    local q = bar -- old solver: string, new solver: unknown
end
@JohnnyMorganz JohnnyMorganz added the bug Something isn't working label Nov 9, 2024
@JohnnyMorganz JohnnyMorganz changed the title New solver: explicitly typed table (e.g., for OOP) does not apply types onto methods New solver: explicitly typed table does not apply types onto function/method declarations Nov 9, 2024
@JohnnyMorganz
Copy link
Contributor Author

This also fails for static functions:

type Tbl = {
  func: (string) -> number
}

local Impl = {} :: Tbl

function Impl.func(x)
   -- old solver: x is string, new solver: x is unknown
end

JohnnyMorganz added a commit to JohnnyMorganz/luau-lsp that referenced this issue Nov 9, 2024
@hgoldstein hgoldstein added the new solver This issue is specific to the new solver. label Nov 12, 2024
@hgoldstein
Copy link
Contributor

Yeah something is not working as I'd expect:

type Tbl = {
  func: (string) -> number
}

local Impl = {} :: Tbl

Impl.func = function(x) end
-- error above! type mismatch

I thought maybe the new solver was being smart and realizing that we had a local table that can be mutated, but no, it's weird that these two examples are misaligned ... I vaguely remember an issue flying by about how the inline function syntax acts differently than assigning a closure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working new solver This issue is specific to the new solver.
Development

No branches or pull requests

2 participants