Skip to content

Commit

Permalink
Autocomplete Free State TableType entryMap change
Browse files Browse the repository at this point in the history
  • Loading branch information
karl-police committed Sep 11, 2024
1 parent a8047b2 commit 2c7ef54
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Analysis/src/Autocomplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,29 @@ static void autocompleteProps(
else
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::Correct
: checkTypeCorrectKind(module, typeArena, builtinTypes, nodes.back(), {{}, {}}, type);
Expand Down
42 changes: 42 additions & 0 deletions tests/Autocomplete.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,48 @@ TEST_CASE_FIXTURE(ACFixture, "dont_offer_any_suggestions_from_within_a_broken_co
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")
{
check(R"(
Expand Down

0 comments on commit 2c7ef54

Please sign in to comment.