mirror of
https://github.com/luau-lang/luau.git
synced 2024-11-15 06:15:44 +08:00
Merge branch 'master' into merge
This commit is contained in:
commit
01cbf185e8
@ -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
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user