mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Add FFlag and move test case
This commit is contained in:
parent
c2b3e83b24
commit
2fe4bf91cf
3 changed files with 70 additions and 18 deletions
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -216,7 +216,9 @@ 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(),
|
||||||
|
[](const TypeError& e)
|
||||||
|
{
|
||||||
return nullptr != get<FunctionRequiresSelf>(e);
|
return nullptr != get<FunctionRequiresSelf>(e);
|
||||||
});
|
});
|
||||||
REQUIRE(it != result.errors.end());
|
REQUIRE(it != result.errors.end());
|
||||||
|
@ -261,7 +263,9 @@ 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(),
|
||||||
|
[](const TypeError& e)
|
||||||
|
{
|
||||||
return nullptr != get<FunctionDoesNotTakeSelf>(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();
|
||||||
|
|
Loading…
Add table
Reference in a new issue