Luau Recap: April 2022

Luau is our new language that you can read more about at https://luau-lang.org.

It’s been a bit of a quiet month. We mostly have small optimizations and bug fixes for you.


You can now define functions on sealed tables that have string indexers. These functions will be type-checked against the indexer type. For example, the following is now valid:


local a : {[string]: () -> number} = {}

function a.y() return 4 end -- OK

Autocomplete will now provide string literal suggestions for singleton types, for example:


local function f(x: "a" | "b") end

f("_") -- suggest "a" and "b"

Improve error recovery in the case where we encounter a type pack variable in a place where one is not allowed, for example: type Foo<A...> = { value: A... }

Error feedback has been improved when code does not pass enough arguments to a variadic function.

For example, the following script now produces a much nicer error message:


type A = { [number]: number }

type B = { [number]: string }

local a: A = { 1, 2, 3 }

-- ERROR: Type 'A' could not be converted into 'B'

-- caused by:

-- Property '[indexer value]' is not compatible. Type 'number' could not be converted into 'string'

local b: B = a

If the following code were to error because Hello was undefined, we would erroneously include the comment in the span of the error. This is now fixed.


type Foo = Hello -- some comment over here

Fixed a crash that could occur when strict scripts have cyclic require() dependencies.

Added an option to autocomplete to cause it to abort processing after a certain amount of time has elapsed.

77 Likes

This topic was automatically opened after 9 minutes.

Really love the improvements to Luau, Every update pushes us further and further toward the true type of safety. Any plans to add type checking to remote events :smile:?

24 Likes

Oh sweet, can’t wait to see what Luau is going to look like and how it will perform in the far future.
The language really seems to develop pretty well.

8 Likes

Looks like a regression with metatable handling. table library functions no longer accept arrays with metatables.

2 Likes

This is a recap of everything that was added over the course of April for Luau, this has nothing to do with the servers.

4 Likes

Great improvements, hope to see more features that improve workflow in the future!

1 Like

I <3 the team that works on luau
thank you for all the updates!

4 Likes

Enable highlights : ). And great! knowing i didnt understand anything but eh still pretty good.

1 Like

This will incorrectly warn with “Expected type table, got ‘Instance’ instead”.

local function execute(object: Instance, name: string)
	print(object[name])
end

This won’t occur if the object is explicitly specified, so this will correctly not warn.

local function execute(name: string)
	print(workspace[name])
end

This will incorrectly warn and I have filed an issue.

--!strict
type value = {true}?
local value: value = {true}
value = value
1 Like

Can you elaborate on this? I’m not sure if you’re talking about runtime behavior or type checking. In terms of runtime behavior table. functions in Luau never used metamethods like __index and we currently have no plans to change it.

1 Like

Referring to type checking. Today if I write

--!strict
local t = setmetatable({} :: {Instance}, {__mode='v'})
table.insert(t, workspace)

I get Type 't' could not be converted into '{a}'
This happens for all table library functions as far as I can tell. I didn’t see it before this update.

4 Likes

I think about that maybe we should fix today show me a script and I will fix it today

1 Like

literal suggestions is really nice ,However the autocomplete
can get really messy with all the suggestions.

Problem :
image


I think you could just hide it or give us some way to do so.
while still keeping the suggestions ,of course.

Hidden :
image

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.