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(LuauAlwaysCommitInferencesOfFunctionCalls, false)
|
||||
LUAU_FASTFLAG(LuauParseDeclareClassIndexer)
|
||||
LUAU_FASTFLAGVARIABLE(LuauIndexTableIntersectionStringExpr, false)
|
||||
|
||||
namespace Luau
|
||||
{
|
||||
|
@ -3412,7 +3413,7 @@ TypeId TypeChecker::checkLValueBinding(const ScopePtr& scope, const AstExprIndex
|
|||
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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -216,9 +216,11 @@ TEST_CASE_FIXTURE(Fixture, "used_dot_instead_of_colon")
|
|||
local a = T.method()
|
||||
)");
|
||||
|
||||
auto it = std::find_if(result.errors.begin(), result.errors.end(), [](const TypeError& e) {
|
||||
return nullptr != get<FunctionRequiresSelf>(e);
|
||||
});
|
||||
auto it = std::find_if(result.errors.begin(), result.errors.end(),
|
||||
[](const TypeError& e)
|
||||
{
|
||||
return nullptr != get<FunctionRequiresSelf>(e);
|
||||
});
|
||||
REQUIRE(it != result.errors.end());
|
||||
}
|
||||
|
||||
|
@ -261,9 +263,11 @@ TEST_CASE_FIXTURE(Fixture, "used_colon_instead_of_dot")
|
|||
local a = T:method()
|
||||
)");
|
||||
|
||||
auto it = std::find_if(result.errors.begin(), result.errors.end(), [](const TypeError& e) {
|
||||
return nullptr != get<FunctionDoesNotTakeSelf>(e);
|
||||
});
|
||||
auto it = std::find_if(result.errors.begin(), result.errors.end(),
|
||||
[](const TypeError& e)
|
||||
{
|
||||
return nullptr != get<FunctionDoesNotTakeSelf>(e);
|
||||
});
|
||||
REQUIRE(it != result.errors.end());
|
||||
}
|
||||
|
||||
|
@ -3642,34 +3646,51 @@ end
|
|||
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"(
|
||||
type Foo = {
|
||||
Bar: string,
|
||||
} & { Baz: number }
|
||||
Enabled: boolean,
|
||||
Size: number,
|
||||
}
|
||||
|
||||
local x: Foo = { Bar = "1", Baz = 2 }
|
||||
local y = x.Bar
|
||||
type Bar = {
|
||||
Enabled: boolean,
|
||||
Width: number,
|
||||
Height: number,
|
||||
}
|
||||
|
||||
local x: Foo | Bar = { Enabled = true, Size = 5 }
|
||||
|
||||
x.Enabled = false
|
||||
)");
|
||||
|
||||
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"(
|
||||
type Foo = {
|
||||
Bar: string,
|
||||
} & { Baz: number }
|
||||
Enabled: boolean,
|
||||
Size: number,
|
||||
}
|
||||
|
||||
local x: Foo = { Bar = "1", Baz = 2 }
|
||||
local y = x["Bar"]
|
||||
type 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();
|
||||
|
|
Loading…
Add table
Reference in a new issue