Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocomplete - Prevent TableState:Free properties with no writeTy to show up when requesting properties from an AST Index #1392

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading