Merge branch 'master' into merge

This commit is contained in:
Andy Friesen 2023-07-07 10:14:46 -07:00
commit 01cbf185e8
3 changed files with 49 additions and 0 deletions

View File

@ -41,6 +41,7 @@ LUAU_FASTFLAGVARIABLE(LuauTinyControlFlowAnalysis, false)
LUAU_FASTFLAGVARIABLE(LuauTypecheckClassTypeIndexers, false)
LUAU_FASTFLAGVARIABLE(LuauAlwaysCommitInferencesOfFunctionCalls, false)
LUAU_FASTFLAG(LuauParseDeclareClassIndexer)
LUAU_FASTFLAGVARIABLE(LuauIndexTableIntersectionStringExpr, false)
namespace Luau
{
@ -3412,6 +3413,20 @@ TypeId TypeChecker::checkLValueBinding(const ScopePtr& scope, const AstExprIndex
return prop->type();
}
}
else if (FFlag::LuauIndexTableIntersectionStringExpr && get<IntersectionType>(exprType))
{
Name name = std::string(value->value.data, value->value.size);
if (std::optional<TypeId> ty = getIndexTypeFromType(scope, exprType, name, expr.location, /* addErrors= */ false))
return *ty;
// If intersection has a table part, report that it cannot be extended just as a sealed table
if (isTableIntersection(exprType))
{
reportError(TypeError{expr.location, CannotExtendTable{exprType, CannotExtendTable::Property, name}});
return errorRecoveryType(scope);
}
}
}
else
{

View File

@ -675,6 +675,10 @@ int replMain(int argc, char** argv)
setLuauFlagsDefault();
#ifdef _WIN32
SetConsoleOutputCP(CP_UTF8);
#endif
int profile = 0;
bool coverage = false;
bool interactive = false;

View File

@ -880,4 +880,34 @@ TEST_CASE_FIXTURE(Fixture, "less_greedy_unification_with_intersection_types_2")
CHECK_EQ("({| x: number |} & {| x: string |}) -> never", toString(requireType("f")));
}
TEST_CASE_FIXTURE(BuiltinsFixture, "index_property_table_intersection_1")
{
CheckResult result = check(R"(
type Foo = {
Bar: string,
} & { Baz: number }
local x: Foo = { Bar = "1", Baz = 2 }
local y = x.Bar
)");
LUAU_REQUIRE_NO_ERRORS(result);
}
TEST_CASE_FIXTURE(BuiltinsFixture, "index_property_table_intersection_2")
{
ScopedFastFlag sff{"LuauIndexTableIntersectionStringExpr", true};
CheckResult result = check(R"(
type Foo = {
Bar: string,
} & { Baz: number }
local x: Foo = { Bar = "1", Baz = 2 }
local y = x["Bar"]
)");
LUAU_REQUIRE_NO_ERRORS(result);
}
TEST_SUITE_END();