mirror of
https://github.com/luau-lang/luau.git
synced 2025-01-19 17:28:06 +00:00
Merge branch 'master' into merge
This commit is contained in:
commit
23e9fa53cd
3 changed files with 26 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,5 +1,6 @@
|
||||||
/build/
|
/build/
|
||||||
/build[.-]*/
|
/build[.-]*/
|
||||||
|
/out
|
||||||
/cmake/
|
/cmake/
|
||||||
/cmake[.-]*/
|
/cmake[.-]*/
|
||||||
/coverage/
|
/coverage/
|
||||||
|
|
|
@ -2041,6 +2041,12 @@ TypeFunctionReductionResult<TypeId> keyofFunctionImpl(
|
||||||
for (std::string key : keys)
|
for (std::string key : keys)
|
||||||
singletons.push_back(ctx->arena->addType(SingletonType{StringSingleton{key}}));
|
singletons.push_back(ctx->arena->addType(SingletonType{StringSingleton{key}}));
|
||||||
|
|
||||||
|
// If there's only one entry, we don't need a UnionType.
|
||||||
|
// We can take straight take it from the first entry
|
||||||
|
// because it was added into the type arena already.
|
||||||
|
if (singletons.size() == 1)
|
||||||
|
return {singletons.front(), false, {}, {}};
|
||||||
|
|
||||||
return {ctx->arena->addType(UnionType{singletons}), false, {}, {}};
|
return {ctx->arena->addType(UnionType{singletons}), false, {}, {}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -388,6 +388,25 @@ TEST_CASE_FIXTURE(BuiltinsFixture, "keyof_type_function_works_with_metatables")
|
||||||
CHECK_EQ("\"w\" | \"x\" | \"y\" | \"z\"", toString(tpm->givenTp));
|
CHECK_EQ("\"w\" | \"x\" | \"y\" | \"z\"", toString(tpm->givenTp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE_FIXTURE(BuiltinsFixture, "keyof_single_entry_no_uniontype")
|
||||||
|
{
|
||||||
|
if (!FFlag::LuauSolverV2)
|
||||||
|
return;
|
||||||
|
|
||||||
|
CheckResult result = check(R"(
|
||||||
|
local tbl_A = { abc = "value" }
|
||||||
|
local tbl_B = { a1 = nil, ["a2"] = nil }
|
||||||
|
|
||||||
|
type keyof_A = keyof<typeof(tbl_A)>
|
||||||
|
type keyof_B = keyof<typeof(tbl_B)>
|
||||||
|
)");
|
||||||
|
|
||||||
|
LUAU_REQUIRE_NO_ERRORS(result);
|
||||||
|
|
||||||
|
CHECK(toString(requireTypeAlias("keyof_A")) == "\"abc\"");
|
||||||
|
CHECK(toString(requireTypeAlias("keyof_B")) == "\"a1\" | \"a2\"");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE_FIXTURE(BuiltinsFixture, "keyof_type_function_errors_if_it_has_nontable_part")
|
TEST_CASE_FIXTURE(BuiltinsFixture, "keyof_type_function_errors_if_it_has_nontable_part")
|
||||||
{
|
{
|
||||||
if (!FFlag::LuauSolverV2)
|
if (!FFlag::LuauSolverV2)
|
||||||
|
|
Loading…
Reference in a new issue