tl
tl copied to clipboard
[next] interface methods
Currently is possible to add functions and methods to interfaces, however, as discussed on Matrix:
Functions are meant to be allowed in interfaces, but only as field declarations, not as standalone
function
entries
Interestingly however, it typechecks as a feature:
local interface IFoo
t: string
end
function IFoo:print()
end
local record Foo
is IFoo
end
-- error: type signature of 'print' does not match its declaration in Foo: argument 0: Foo is not a IFoo
-- changing to Foo.print(self: IFOO) works though
function Foo:print()
print(self.t)
end
local function bar(v: IFoo)
-- currently accepted by tl (next-branch) because of `IFoo:print` method
v:print()
end
local f: Foo = setmetatable({ t = "hey" }, { __index = Foo })
bar(f)