Skip to content

Commit 455da69

Browse files
committed
Autocomplete Free State TableType entryMap change
1 parent a8047b2 commit 455da69

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

Analysis/src/Autocomplete.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,29 @@ static void autocompleteProps(
303303
else
304304
type = follow(prop.type());
305305

306+
307+
// If a "TableType" is a "Free State"
308+
// Somehow readTy only properties get added into it
309+
// This part removes them if writeTy is empty
310+
//
311+
// This gets rid of unassigned properties in the autocomplete.
312+
if (FFlag::LuauSolverV2)
313+
{
314+
if (auto tblTy = get<TableType>(rootTy))
315+
{
316+
// This probably won't assure for nested tables?
317+
if (tblTy->state == TableState::Free)
318+
{
319+
// If this property was never written to.
320+
if (prop.writeTy == std::nullopt)
321+
{
322+
continue; // Skip this
323+
}
324+
}
325+
}
326+
}
327+
328+
306329
TypeCorrectKind typeCorrect = indexType == PropIndexType::Key
307330
? TypeCorrectKind::Correct
308331
: checkTypeCorrectKind(module, typeArena, builtinTypes, nodes.back(), {{}, {}}, type);

tests/Autocomplete.test.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,48 @@ TEST_CASE_FIXTURE(ACFixture, "dont_offer_any_suggestions_from_within_a_broken_co
650650
CHECK_EQ(ac.context, AutocompleteContext::Unknown);
651651
}
652652

653+
TEST_CASE_FIXTURE(ACBuiltinsFixture, "autocomplete_freetable_shows_nullopt_writeTy_outsideOfFuncScope_fix")
654+
{
655+
TypeArena arena;
656+
frontend.globals.globalScope->exportedTypeBindings["FreeTable"] = TypeFun{{}, arena.addType(TableType{TableState::Free, TypeLevel{}})};
657+
658+
// This fix only works for the new type solver.
659+
if (!FFlag::LuauSolverV2)
660+
return;
661+
662+
CheckResult check1 = check(R"(
663+
local tbl_A = {} :: FreeTable
664+
tbl_A.abc = 1
665+
666+
print(tbl_A.notWritingTo)
667+
668+
function test(a)
669+
a.@3
670+
if (a.propertyTest) then return true end
671+
return false
672+
end
673+
674+
test({@2})
675+
676+
tbl_A.@1
677+
)");
678+
679+
auto test1 = toString(requireType("tbl_A"));
680+
auto test2 = requireType("tbl_A");
681+
682+
auto ac1 = autocomplete('1');
683+
684+
auto ac2 = autocomplete('2');
685+
auto ac3 = autocomplete('3');
686+
687+
// tbl_A indexing, the main problem that is to fix.
688+
CHECK_EQ(ac1.entryMap.count("abc"), 1);
689+
CHECK_EQ(ac1.entryMap.count("notWritingTo"), 0);
690+
691+
// when within function({})
692+
CHECK_EQ(ac2.entryMap.count("propertyTest"), 1);
693+
}
694+
653695
TEST_CASE_FIXTURE(ACFixture, "autocomplete_for_middle_keywords")
654696
{
655697
check(R"(

0 commit comments

Comments
 (0)