luau/docs/_posts/2022-01-27-luau-recap-january-2022.md
Andy Friesen c38c75a985
Update docs/_posts/2022-01-27-luau-recap-january-2022.md
Co-authored-by: Arseny Kapoulkine <arseny.kapoulkine@gmail.com>
2022-01-28 11:41:31 -08:00

3.3 KiB

layout title
single Luau Recap: January 2022

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

[Cross-posted to the Roblox Developer Forum.]

New tostring implementation

This change replaces the default number->string conversion with a new algorithm called Schubfach, which allows us to produce the shortest precise round-trippable representation of any input number very quickly.

While performance is not the main driving factor, this also happens to be significantly faster than our old implementation (up to 10x depending on the number and the platform). the bottleneck there.

Improvements to type assertions

The :: type assertion operator can now be used to coerce a value between any two related types. Previously, it could only be used for downcasts or casts to any. The following used to be invalid, but is now valid:

local t = {x=0, y=0}
local a = t :: {x: number}

Typechecking improvements

An issue surrounding table literals and indexers has been fixed:

type RecolorMap = {[string]: RecolorMap | Color3}

local hatRecolorMap: RecolorMap = {
    Brim = Color3.fromRGB(255, 0, 0), -- We used to report an error here
    Top = Color3.fromRGB(255, 0, 0)
}

Accessing a property whose base expression was previously refined will now return the correct result.

Error reporting improvements

When a type error involves a union (or an option), we now provide more context in the error message.

For instance, given the following code:

--!strict

type T = {x: number}

local x: T? = {w=4}

We now report the following:

Type 'x' could not be converted into 'T?'
caused by:
  None of the union options are compatible. For example: Table type 'x' not compatible with type 'T' because the former is missing field 'x'

Luau now gives up and reports an *unknown* type in far fewer cases when typechecking programs that have type errors.

New APIs

We have brought in the coroutine.close function from Lua 5.4. It accepts a suspended coroutine and marks it as non-runnable. In Roblox, this can be useful in combination with task.defer to implement cancellation.

REPL improvements

Added --interactive option to run the REPL after running the last script file.

Allowed the compiler optimization level to be specified.

Allowed methods to be tab completed

Allowed methods on string instances to be completed

Improved Luau REPL argument parsing and error reporting

Input history is now saved/loaded

Thanks

A special thanks from all the fine folks who contributed PRs over the last few months!