luau-lang / luau

A fast, small, safe, gradually typed embeddable scripting language derived from Lua
https://luau.org
MIT License
4.08k stars 382 forks source link

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

Open JohnnyMorganz opened 2 weeks ago

JohnnyMorganz commented 2 weeks ago

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 commented 2 weeks ago

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
hgoldstein commented 2 weeks ago

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.