mirror of
https://github.com/luau-lang/luau.git
synced 2025-08-26 11:27:08 +01:00
## What's Changed? This week we have an update with an implementation for one of the RFCs we had approved before, an improvement of the new type solver and a small Lua 5.1 C API compatibility improvement. * `@deprecated` attribute can now have a custom suggestion for a replacement and a reason message as described in [deprecated attribute parameters RFC](https://rfcs.luau.org/syntax-attribute-functions-deprecated.html) For example: ```luau @[deprecated {reason = "foo suffers from performance issues", use = "bar"}] local function foo() ... end -- Function 'foo' is deprecated, use 'bar' instead. foo suffers from performance issues foo() ``` * `lua_cpcall` C API function has been restored both for compatibility with Lua 5.1 and as a safe way to enter protected call environment to work with Luau C API functions that may error Instead of ``` if (!lua_checkstack(L, 2)) return -1; lua_pushcfunction(L, test, nullptr); lua_pushlightuserdata(L, context); int status = lua_pcall(L, 1, 0, 0); ``` you can simply do ``` int status = lua_cpcall(L, test, context); ``` * In Luau CLI, required module return values can now have any type ## New Type Solver - Additional improvements on type refinements used with external types should fix some reported false positive errors where types refined to `never` - Fixed an issue in recursive refinement types in a form of `t1 where t1 = refine<t1, _>` getting 'stuck' - Fixed an issue in subtyping of generic functions, it is now possible to assign `<T>(T, (T) -> T) -> T` to `(number, <X>(X) -> X) -> number` - Fixed an ICE caused by recursive types (Fixes #1686) - Added additional iteration and recursion limits to stop the type solver before system resources are used up ## Internal Contributors Co-authored-by: Andy Friesen <afriesen@roblox.com> Co-authored-by: Annie Tang <annietang@roblox.com> Co-authored-by: Ariel Weiss <aaronweiss@roblox.com> Co-authored-by: Hunter Goldstein <hgoldstein@roblox.com> Co-authored-by: Ilya Rezvov <irezvov@roblox.com> Co-authored-by: Sora Kanosue <skanosue@roblox.com> Co-authored-by: Vighnesh Vijay <vvijay@roblox.com> Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
90 lines
2 KiB
C++
90 lines
2 KiB
C++
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
#include "Fixture.h"
|
|
|
|
#include "Luau/ToString.h"
|
|
#include "doctest.h"
|
|
#include "Luau/Common.h"
|
|
#include "ScopedFlags.h"
|
|
|
|
using namespace Luau;
|
|
|
|
LUAU_FASTFLAG(LuauEagerGeneralization4)
|
|
LUAU_FASTFLAG(LuauTrackFreeInteriorTypePacks)
|
|
LUAU_FASTFLAG(LuauResetConditionalContextProperly)
|
|
|
|
namespace
|
|
{
|
|
|
|
struct NegationFixture : Fixture
|
|
{
|
|
TypeArena arena;
|
|
|
|
NegationFixture()
|
|
{
|
|
registerHiddenTypes(getFrontend());
|
|
}
|
|
};
|
|
|
|
} // namespace
|
|
|
|
TEST_SUITE_BEGIN("Negations");
|
|
|
|
TEST_CASE_FIXTURE(NegationFixture, "negated_string_is_a_subtype_of_string")
|
|
{
|
|
CheckResult result = check(R"(
|
|
function foo(arg: string) end
|
|
local a: string & Not<"Hello">
|
|
foo(a)
|
|
)");
|
|
|
|
LUAU_REQUIRE_NO_ERRORS(result);
|
|
}
|
|
|
|
TEST_CASE_FIXTURE(NegationFixture, "string_is_not_a_subtype_of_negated_string")
|
|
{
|
|
CheckResult result = check(R"(
|
|
function foo(arg: string & Not<"hello">) end
|
|
local a: string
|
|
foo(a)
|
|
)");
|
|
|
|
LUAU_REQUIRE_ERROR_COUNT(1, result);
|
|
}
|
|
|
|
TEST_CASE_FIXTURE(Fixture, "cofinite_strings_can_be_compared_for_equality")
|
|
{
|
|
ScopedFastFlag sff[] = {
|
|
{FFlag::LuauEagerGeneralization4, true},
|
|
{FFlag::LuauTrackFreeInteriorTypePacks, true},
|
|
{FFlag::LuauResetConditionalContextProperly, true}
|
|
};
|
|
|
|
CheckResult result = check(R"(
|
|
function f(e)
|
|
if e == 'strictEqual' then
|
|
e = 'strictEqualObject'
|
|
end
|
|
if e == 'deepStrictEqual' or e == 'strictEqual' then
|
|
elseif e == 'notDeepStrictEqual' or e == 'notStrictEqual' then
|
|
end
|
|
return e
|
|
end
|
|
)");
|
|
|
|
LUAU_REQUIRE_NO_ERRORS(result);
|
|
CHECK("(string) -> string" == toString(requireType("f")));
|
|
}
|
|
|
|
TEST_CASE_FIXTURE(NegationFixture, "compare_cofinite_strings")
|
|
{
|
|
CheckResult result = check(R"(
|
|
local u : Not<"a">
|
|
local v : "b"
|
|
if u == v then
|
|
end
|
|
)");
|
|
LUAU_REQUIRE_NO_ERRORS(result);
|
|
}
|
|
|
|
TEST_SUITE_END();
|