mirror of
https://github.com/luau-lang/luau.git
synced 2024-11-15 06:15:44 +08:00
b23d43496b
### What's new * Light update this week, mostly fast flag cleanups. ### New Solver * Rename flag to enable new solver from `DebugLuauDeferredConstraintResolution` to `LuauSolverV2` * Added support for magic functions for the new type checker (as opposed to the type inference component) * Improved handling of `string.format` with magic function improvements * Cleaning up some of the reported errors by the new type checker * Minor refactoring of `TypeChecker2.cpp` that happens to make the diff very hard to read. --- ### Internal Contributors Co-authored-by: Aaron Weiss <aaronweiss@roblox.com> Co-authored-by: Andy Friesen <afriesen@roblox.com> Co-authored-by: Vighnesh Vijay <vvijay@roblox.com> Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com> --------- Co-authored-by: Alexander McCord <amccord@roblox.com> Co-authored-by: Andy Friesen <afriesen@roblox.com> Co-authored-by: Vighnesh <vvijay@roblox.com> Co-authored-by: Aviral Goel <agoel@roblox.com> Co-authored-by: David Cope <dcope@roblox.com> Co-authored-by: Lily Brown <lbrown@roblox.com> Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com> Co-authored-by: Junseo Yoo <jyoo@roblox.com>
83 lines
1.8 KiB
C++
83 lines
1.8 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;
|
|
|
|
namespace
|
|
{
|
|
|
|
struct NegationFixture : Fixture
|
|
{
|
|
TypeArena arena;
|
|
|
|
NegationFixture()
|
|
{
|
|
registerHiddenTypes(&frontend);
|
|
}
|
|
};
|
|
|
|
} // 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")
|
|
{
|
|
// CLI-117082 Cofinite strings cannot be compared for equality because normalization produces a large type with cycles
|
|
if (FFlag::LuauSolverV2)
|
|
return;
|
|
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();
|