Add FFlag and move test case

This commit is contained in:
JohnnyMorganz 2023-07-05 12:05:35 +01:00
parent c2b3e83b24
commit 2fe4bf91cf
3 changed files with 70 additions and 18 deletions

View file

@ -41,6 +41,7 @@ LUAU_FASTFLAGVARIABLE(LuauTinyControlFlowAnalysis, false)
LUAU_FASTFLAGVARIABLE(LuauTypecheckClassTypeIndexers, false) LUAU_FASTFLAGVARIABLE(LuauTypecheckClassTypeIndexers, false)
LUAU_FASTFLAGVARIABLE(LuauAlwaysCommitInferencesOfFunctionCalls, false) LUAU_FASTFLAGVARIABLE(LuauAlwaysCommitInferencesOfFunctionCalls, false)
LUAU_FASTFLAG(LuauParseDeclareClassIndexer) LUAU_FASTFLAG(LuauParseDeclareClassIndexer)
LUAU_FASTFLAGVARIABLE(LuauIndexTableIntersectionStringExpr, false)
namespace Luau namespace Luau
{ {
@ -3412,7 +3413,7 @@ TypeId TypeChecker::checkLValueBinding(const ScopePtr& scope, const AstExprIndex
return prop->type(); return prop->type();
} }
} }
else if (get<IntersectionType>(exprType)) else if (FFlag::LuauIndexTableIntersectionStringExpr && get<IntersectionType>(exprType))
{ {
Name name = std::string(value->value.data, value->value.size); Name name = std::string(value->value.data, value->value.size);

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"))); 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(); TEST_SUITE_END();

View file

@ -216,9 +216,11 @@ TEST_CASE_FIXTURE(Fixture, "used_dot_instead_of_colon")
local a = T.method() local a = T.method()
)"); )");
auto it = std::find_if(result.errors.begin(), result.errors.end(), [](const TypeError& e) { auto it = std::find_if(result.errors.begin(), result.errors.end(),
return nullptr != get<FunctionRequiresSelf>(e); [](const TypeError& e)
}); {
return nullptr != get<FunctionRequiresSelf>(e);
});
REQUIRE(it != result.errors.end()); REQUIRE(it != result.errors.end());
} }
@ -261,9 +263,11 @@ TEST_CASE_FIXTURE(Fixture, "used_colon_instead_of_dot")
local a = T:method() local a = T:method()
)"); )");
auto it = std::find_if(result.errors.begin(), result.errors.end(), [](const TypeError& e) { auto it = std::find_if(result.errors.begin(), result.errors.end(),
return nullptr != get<FunctionDoesNotTakeSelf>(e); [](const TypeError& e)
}); {
return nullptr != get<FunctionDoesNotTakeSelf>(e);
});
REQUIRE(it != result.errors.end()); REQUIRE(it != result.errors.end());
} }
@ -3642,34 +3646,51 @@ end
LUAU_REQUIRE_NO_ERRORS(result); LUAU_REQUIRE_NO_ERRORS(result);
} }
TEST_CASE_FIXTURE(BuiltinsFixture, "index_property_table_intersection_1") TEST_CASE_FIXTURE(BuiltinsFixture, "write_common_property_to_table_unions")
{ {
CheckResult result = check(R"( CheckResult result = check(R"(
type Foo = { type Foo = {
Bar: string, Enabled: boolean,
} & { Baz: number } Size: number,
}
local x: Foo = { Bar = "1", Baz = 2 } type Bar = {
local y = x.Bar Enabled: boolean,
Width: number,
Height: number,
}
local x: Foo | Bar = { Enabled = true, Size = 5 }
x.Enabled = false
)"); )");
LUAU_REQUIRE_NO_ERRORS(result); LUAU_REQUIRE_NO_ERRORS(result);
} }
TEST_CASE_FIXTURE(BuiltinsFixture, "index_property_table_intersection_2") TEST_CASE_FIXTURE(BuiltinsFixture, "write_common_property_to_table_unions_2")
{ {
CheckResult result = check(R"( CheckResult result = check(R"(
type Foo = { type Foo = {
Bar: string, Enabled: boolean,
} & { Baz: number } Size: number,
}
local x: Foo = { Bar = "1", Baz = 2 } type Bar = {
local y = x["Bar"] Enabled: boolean,
Width: number,
Height: number,
}
local x: Foo | Bar = { Enabled = true, Size = 5 }
x.Size = 6
)"); )");
LUAU_REQUIRE_NO_ERRORS(result); LUAU_REQUIRE_ERROR_COUNT(1, result);
CHECK_EQ("error", toString(result.errors[0])); // TODO
} }
TEST_SUITE_END(); TEST_SUITE_END();