Autocomplete Free State TableType entryMap change

This commit is contained in:
karl-police 2024-09-11 01:34:12 +02:00
parent a8047b2e46
commit 2c7ef54984
2 changed files with 65 additions and 0 deletions

View File

@ -303,6 +303,29 @@ static void autocompleteProps(
else else
type = follow(prop.type()); type = follow(prop.type());
// If a "TableType" is a "Free State"
// Somehow readTy only properties get added into it
// This part removes them if writeTy is empty
//
// This gets rid of unassigned properties in the autocomplete.
if (FFlag::LuauSolverV2)
{
if (auto tblTy = get<TableType>(rootTy))
{
// This probably won't assure for nested tables?
if (tblTy->state == TableState::Free)
{
// If this property was never written to.
if (prop.writeTy == std::nullopt)
{
continue; // Skip this
}
}
}
}
TypeCorrectKind typeCorrect = indexType == PropIndexType::Key TypeCorrectKind typeCorrect = indexType == PropIndexType::Key
? TypeCorrectKind::Correct ? TypeCorrectKind::Correct
: checkTypeCorrectKind(module, typeArena, builtinTypes, nodes.back(), {{}, {}}, type); : checkTypeCorrectKind(module, typeArena, builtinTypes, nodes.back(), {{}, {}}, type);

View File

@ -650,6 +650,48 @@ TEST_CASE_FIXTURE(ACFixture, "dont_offer_any_suggestions_from_within_a_broken_co
CHECK_EQ(ac.context, AutocompleteContext::Unknown); CHECK_EQ(ac.context, AutocompleteContext::Unknown);
} }
TEST_CASE_FIXTURE(ACBuiltinsFixture, "autocomplete_freetable_shows_nullopt_writeTy_outsideOfFuncScope_fix")
{
TypeArena arena;
frontend.globals.globalScope->exportedTypeBindings["FreeTable"] = TypeFun{{}, arena.addType(TableType{TableState::Free, TypeLevel{}})};
// This fix only works for the new type solver.
if (!FFlag::LuauSolverV2)
return;
CheckResult check1 = check(R"(
local tbl_A = {} :: FreeTable
tbl_A.abc = 1
print(tbl_A.notWritingTo)
function test(a)
a.@3
if (a.propertyTest) then return true end
return false
end
test({@2})
tbl_A.@1
)");
//auto test1 = toString(requireType("tbl_A"));
//auto test2 = requireType("tbl_A");
auto ac1 = autocomplete('1');
auto ac2 = autocomplete('2');
//auto ac3 = autocomplete('3');
// tbl_A indexing, the main problem that is to fix.
CHECK_EQ(ac1.entryMap.count("abc"), 1);
CHECK_EQ(ac1.entryMap.count("notWritingTo"), 0);
// when within function({})
CHECK_EQ(ac2.entryMap.count("propertyTest"), 1);
}
TEST_CASE_FIXTURE(ACFixture, "autocomplete_for_middle_keywords") TEST_CASE_FIXTURE(ACFixture, "autocomplete_for_middle_keywords")
{ {
check(R"( check(R"(