news-2022-02-28-luau-recap-february-2022.md
February 28, 2022
We have introduced a syntax to provide default type arguments inside the type alias type parameter list.
It is now possible to have type functions where the instantiation can omit some type arguments.
You can provide concrete types:
Or reference parameters defined earlier in the list:
Type pack parameters can also have a default type pack:
If all type parameters have a default type, it is now possible to reference that without providing any type arguments:
For more details, you can read the original RFC proposal.
This month we had many fixes to improve our type inference and reduce false positive errors.
if-then-else expression can now have different types in each branch:
And if the expected result type is known, you will not get an error in cases like these:
assert result is now known to not be ‘falsy’ (false or nil):
We fixed cases where length operator # reported an error when used on a compatible type:
Functions with different variadic argument/return types are no longer compatible:
We have also fixed:
A new static analysis warning was introduced to mark incorrect use of a ‘a and b or c’ pattern. When ‘b’ is ‘falsy’ (false or nil), result will always be ‘c’, even if the expression ‘a’ was true:
Like we say in the warning, new if-then-else expression doesn’t have this pitfall:
We have also introduced a check for misspelled comment directives:
For performance, we have changed how our Garbage Collector collects unreachable memory.
This rework makes it possible to free memory 2.5x faster and also comes with a small change to how we store Luau objects in memory. For example, each table now uses 16 fewer bytes on 64-bit platforms.
Another optimization was made for select(_, ...) call.
It is now using a special fast path that has constant-time complexity in number of arguments (~3x faster with 10 arguments).
A special thanks to all the fine folks who contributed PRs this month!