luau/tests/TypeInfer.negations.test.cpp
Hunter Goldstein 6ff0650a8d
Sync to upstream/release/682 (#1912)
# What's changed?

Another somewhat quiet week! Don't let the large PR fool you, this is
mostly ...

## New Solver
* The code for type functions has been re-organized: instead of
_everything_ living in `TypeFunction.h` and `TypeFunction.cpp`, we now
have separate files for the type function inference machinery
(`TypeFunction.h`), definitions of built-in type functions
(`BuiltinTypeFunctions.h`), and the implementation of user defined type
functions (`UserDefinedTypeFunction.h`).
* Refinements against `*no-refine*`, a sentinel type indicating that no
refinements should occur, are now _always_ resolved, even if the target
of the refinement would be otherwise pending, such as another type
function.

## Autocomplete
* Fixed autocomplete to prefer table property completion to string
singleton completion. In the below example, the types associated with
each member of `foo` will be displayed in autocomplete popups.
```
local foo = {
    ["Item/Foo"] = 42,
    ["Item/Bar"] = "it's true",
    ["Item/Baz"] = true,
}
foo["|"] -- cursor at `|`
```

## Native Codegen
* Fixed native compilation lowering of the new global lookup
instruction, which caused code generation to fail with an error or to
evaluate incorrect results. Issue affected 678-681 releases when all
flags were enabled.

---

Co-authored-by: Andy Friesen <afriesen@roblox.com>
Co-authored-by: Ariel Weiss <aaronweiss@roblox.com>
Co-authored-by: Hunter Goldstein <hgoldstein@roblox.com>
Co-authored-by: Sora Kanosue <skanosue@roblox.com>
Co-authored-by: Talha Pathan <tpathan@roblox.com>
Co-authored-by: Vighnesh Vijay <vvijay@roblox.com>
Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
2025-07-11 11:36:47 -07:00

84 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;
LUAU_FASTFLAG(LuauEagerGeneralization4)
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};
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();