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

PrimitiveTypeConstraint force dispatch fix for a ConstraintSolvingIncompleteError case #1419

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
2 changes: 1 addition & 1 deletion Analysis/include/Luau/ConstraintSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ struct ConstraintSolver
bool tryDispatch(const TypeAliasExpansionConstraint& c, NotNull<const Constraint> constraint);
bool tryDispatch(const FunctionCallConstraint& c, NotNull<const Constraint> constraint);
bool tryDispatch(const FunctionCheckConstraint& c, NotNull<const Constraint> constraint);
bool tryDispatch(const PrimitiveTypeConstraint& c, NotNull<const Constraint> constraint);
bool tryDispatch(const PrimitiveTypeConstraint& c, NotNull<const Constraint> constraint, bool force);
bool tryDispatch(const HasPropConstraint& c, NotNull<const Constraint> constraint);


Expand Down
21 changes: 17 additions & 4 deletions Analysis/src/ConstraintSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ bool ConstraintSolver::tryDispatch(NotNull<const Constraint> constraint, bool fo
else if (auto fcc = get<FunctionCheckConstraint>(*constraint))
success = tryDispatch(*fcc, constraint);
else if (auto fcc = get<PrimitiveTypeConstraint>(*constraint))
success = tryDispatch(*fcc, constraint);
success = tryDispatch(*fcc, constraint, force);
else if (auto hpc = get<HasPropConstraint>(*constraint))
success = tryDispatch(*hpc, constraint);
else if (auto spc = get<HasIndexerConstraint>(*constraint))
Expand Down Expand Up @@ -1406,7 +1406,7 @@ bool ConstraintSolver::tryDispatch(const FunctionCheckConstraint& c, NotNull<con
return true;
}

bool ConstraintSolver::tryDispatch(const PrimitiveTypeConstraint& c, NotNull<const Constraint> constraint)
bool ConstraintSolver::tryDispatch(const PrimitiveTypeConstraint& c, NotNull<const Constraint> constraint, bool force)
{
std::optional<TypeId> expectedType = c.expectedType ? std::make_optional<TypeId>(follow(*c.expectedType)) : std::nullopt;
if (expectedType && (isBlocked(*expectedType) || get<PendingExpansionType>(*expectedType)))
Expand All @@ -1422,8 +1422,21 @@ bool ConstraintSolver::tryDispatch(const PrimitiveTypeConstraint& c, NotNull<con
// This is probably the only thing that makes this not insane to do.
if (auto refCount = unresolvedConstraints.find(c.freeType); refCount && *refCount > 1)
{
block(c.freeType, constraint);
return false;
if (force)
{
// If we get force dispatched and are the owner of the constraint
// Then do not block.
if (canMutate(c.freeType, constraint) == false)
{
block(c.freeType, constraint);
return false;
}
}
else
{
block(c.freeType, constraint);
return false;
}
}

TypeId bindTo = c.primitiveType;
Expand Down
18 changes: 18 additions & 0 deletions tests/TypeInfer.primitives.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,24 @@ TEST_CASE_FIXTURE(Fixture, "check_methods_of_number")
}
}

TEST_CASE_FIXTURE(BuiltinsFixture, "primitive_types_issue_IfThenElseIf_union_simplification")
{
if (!FFlag::LuauSolverV2)
return;

CheckResult result = check(R"(
local v1: string?

local stringButItIsHere = "Windows"

v1 = if true then stringButItIsHere
elseif false then "Something"
else "Other"
)");

LUAU_REQUIRE_NO_ERRORS(result);
}

TEST_CASE("singleton_types")
{
BuiltinsFixture a;
Expand Down
Loading