Skip to content

Commit

Permalink
fflag gate
Browse files Browse the repository at this point in the history
  • Loading branch information
checkraisefold committed Nov 2, 2024
1 parent 414d6a4 commit 54e190a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
23 changes: 18 additions & 5 deletions Analysis/src/ConstraintGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ LUAU_DYNAMIC_FASTINT(LuauTypeSolverRelease)
LUAU_FASTFLAG(LuauTypestateBuiltins2)

LUAU_FASTFLAGVARIABLE(LuauNewSolverVisitErrorExprLvalues)
LUAU_FASTFLAGVARIABLE(LuauNewSolverPrePopulateClasses)

namespace Luau
{
Expand Down Expand Up @@ -753,6 +754,9 @@ void ConstraintGenerator::checkAliases(const ScopePtr& scope, AstStatBlock* bloc
}
else if (auto classDeclaration = stat->as<AstStatDeclareClass>())
{
if (!FFlag::LuauNewSolverPrePopulateClasses)
continue;

if (scope->exportedTypeBindings.count(classDeclaration->name.value))
{
auto it = classDefinitionLocations.find(classDeclaration->name.value);
Expand Down Expand Up @@ -1671,7 +1675,7 @@ ControlFlow ConstraintGenerator::visit(const ScopePtr& scope, AstStatDeclareClas
{
// If a class with the same name was already defined, we skip over
auto bindingIt = scope->exportedTypeBindings.find(declaredClass->name.value);
if (bindingIt == scope->exportedTypeBindings.end())
if (FFlag::LuauNewSolverPrePopulateClasses && bindingIt == scope->exportedTypeBindings.end())
return ControlFlow::None;

std::optional<TypeId> superTy = std::make_optional(builtinTypes->classType);
Expand All @@ -1688,9 +1692,12 @@ ControlFlow ConstraintGenerator::visit(const ScopePtr& scope, AstStatDeclareClas

// We don't have generic classes, so this assertion _should_ never be hit.
LUAU_ASSERT(lookupType->typeParams.size() == 0 && lookupType->typePackParams.size() == 0);
superTy = follow(lookupType->type);
if (FFlag::LuauNewSolverPrePopulateClasses)
superTy = follow(lookupType->type);
else
superTy = lookupType->type;

if (!get<ClassType>(*superTy))
if (!get<ClassType>(follow(*superTy)))
{
reportError(
declaredClass->location,
Expand All @@ -1711,8 +1718,14 @@ ControlFlow ConstraintGenerator::visit(const ScopePtr& scope, AstStatDeclareClas

ctv->metatable = metaTy;

TypeId classBindTy = bindingIt->second.type;
emplaceType<BoundType>(asMutable(classBindTy), classTy);

if (FFlag::LuauNewSolverPrePopulateClasses)
{
TypeId classBindTy = bindingIt->second.type;
emplaceType<BoundType>(asMutable(classBindTy), classTy);
}
else
scope->exportedTypeBindings[className] = TypeFun{{}, classTy};

if (declaredClass->indexer)
{
Expand Down
3 changes: 3 additions & 0 deletions tests/TypeInfer.definitions.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

using namespace Luau;

LUAU_FASTFLAG(LuauNewSolverPrePopulateClasses)

TEST_SUITE_BEGIN("DefinitionTests");

TEST_CASE_FIXTURE(Fixture, "definition_file_simple")
Expand Down Expand Up @@ -492,6 +494,7 @@ TEST_CASE_FIXTURE(Fixture, "class_definition_indexer")

TEST_CASE_FIXTURE(Fixture, "class_definitions_reference_other_classes")
{
ScopedFastFlag _{FFlag::LuauNewSolverPrePopulateClasses, true};
loadDefinition(R"(
declare class Channel
Messages: { Message }
Expand Down

0 comments on commit 54e190a

Please sign in to comment.