mirror of
https://github.com/luau-lang/luau.git
synced 2025-03-31 08:50:54 +01:00
Fix singleton parameters in overloaded functions (#1694)
- Fixes #1691 - Fixes #1589 --------- Co-authored-by: Math <175355178+maffeus@users.noreply.github.com> Co-authored-by: ariel <aaronweiss@roblox.com> Co-authored-by: Matheus <175355178+m4fh@users.noreply.github.com> Co-authored-by: ariel <aweiss@hey.com>
This commit is contained in:
parent
5f42e63a73
commit
2621488abe
2 changed files with 34 additions and 2 deletions
|
@ -33,6 +33,7 @@ LUAU_FASTINT(LuauCheckRecursionLimit)
|
|||
LUAU_FASTFLAG(DebugLuauLogSolverToJson)
|
||||
LUAU_FASTFLAG(DebugLuauMagicTypes)
|
||||
LUAU_FASTFLAG(LuauPreserveUnionIntersectionNodeForLeadingTokenSingleType)
|
||||
LUAU_FASTFLAGVARIABLE(LuauPropagateExpectedTypesForCalls)
|
||||
LUAU_FASTFLAG(DebugLuauGreedyGeneralization)
|
||||
|
||||
LUAU_FASTFLAGVARIABLE(LuauTrackInteriorFreeTypesOnScope)
|
||||
|
@ -2148,13 +2149,23 @@ InferencePack ConstraintGenerator::checkPack(const ScopePtr& scope, AstExprCall*
|
|||
}
|
||||
else if (i < exprArgs.size() - 1 || !(arg->is<AstExprCall>() || arg->is<AstExprVarargs>()))
|
||||
{
|
||||
auto [ty, refinement] = check(scope, arg, /*expectedType*/ std::nullopt, /*forceSingleton*/ false, /*generalize*/ false);
|
||||
std::optional<TypeId> expectedType = std::nullopt;
|
||||
if (FFlag::LuauPropagateExpectedTypesForCalls && i < expectedTypesForCall.size())
|
||||
{
|
||||
expectedType = expectedTypesForCall[i];
|
||||
}
|
||||
auto [ty, refinement] = check(scope, arg, expectedType, /*forceSingleton*/ false, /*generalize*/ false);
|
||||
args.push_back(ty);
|
||||
argumentRefinements.push_back(refinement);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto [tp, refis] = checkPack(scope, arg, {});
|
||||
std::vector<std::optional<Luau::TypeId>> expectedTypes = {};
|
||||
if (FFlag::LuauPropagateExpectedTypesForCalls && i < expectedTypesForCall.size())
|
||||
{
|
||||
expectedTypes.insert(expectedTypes.end(), expectedTypesForCall.begin() + i, expectedTypesForCall.end());
|
||||
}
|
||||
auto [tp, refis] = checkPack(scope, arg, expectedTypes);
|
||||
argTail = tp;
|
||||
argumentRefinements.insert(argumentRefinements.end(), refis.begin(), refis.end());
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
using namespace Luau;
|
||||
|
||||
LUAU_FASTFLAG(LuauSolverV2)
|
||||
LUAU_FASTFLAG(LuauPropagateExpectedTypesForCalls)
|
||||
LUAU_FASTFLAG(LuauImproveTypePathsInErrors)
|
||||
|
||||
TEST_SUITE_BEGIN("TypeSingletons");
|
||||
|
@ -152,6 +153,26 @@ TEST_CASE_FIXTURE(Fixture, "overloaded_function_call_with_singletons")
|
|||
LUAU_REQUIRE_NO_ERRORS(result);
|
||||
}
|
||||
|
||||
TEST_CASE_FIXTURE(Fixture, "overloaded_function_resolution_singleton_parameters")
|
||||
{
|
||||
ScopedFastFlag sff{FFlag::LuauPropagateExpectedTypesForCalls, true};
|
||||
|
||||
CheckResult result = check(R"(
|
||||
type A = ("A") -> string
|
||||
type B = ("B") -> number
|
||||
|
||||
local function foo(f: A & B)
|
||||
return f("A"), f("B")
|
||||
end
|
||||
)");
|
||||
LUAU_REQUIRE_NO_ERRORS(result);
|
||||
TypeId t = requireType("foo");
|
||||
const FunctionType* fooType = get<FunctionType>(requireType("foo"));
|
||||
REQUIRE(fooType != nullptr);
|
||||
|
||||
CHECK(toString(t) == "(((\"A\") -> string) & ((\"B\") -> number)) -> (string, number)");
|
||||
}
|
||||
|
||||
TEST_CASE_FIXTURE(Fixture, "overloaded_function_call_with_singletons_mismatch")
|
||||
{
|
||||
DOES_NOT_PASS_NEW_SOLVER_GUARD();
|
||||
|
|
Loading…
Add table
Reference in a new issue