Add failing test case for #1003 & fix error msg

This commit is contained in:
AmberGraceSoftware 2023-08-11 19:50:28 -06:00
parent 0b2755f964
commit de3c7f3348
2 changed files with 38 additions and 0 deletions

View file

@ -43,12 +43,22 @@ LUAU_FASTFLAGVARIABLE(LuauTinyControlFlowAnalysis, false)
LUAU_FASTFLAGVARIABLE(LuauAlwaysCommitInferencesOfFunctionCalls, false)
LUAU_FASTFLAG(LuauParseDeclareClassIndexer)
LUAU_FASTFLAGVARIABLE(LuauIndexTableIntersectionStringExpr, false)
LUAU_FASTFLAGVARIABLE(LuauIntersectedBinopOverloadFix, false)
namespace Luau
{
static bool typeCouldHaveMetatable(TypeId ty)
{
if (FFlag::LuauIntersectedBinopOverloadFix) {
if (auto itv = get<IntersectionType>(follow(ty)))
{
for (TypeId part : itv->parts)
if (typeCouldHaveMetatable(part))
return true;
return false;
}
}
return get<TableType>(follow(ty)) || get<ClassType>(follow(ty)) || get<MetatableType>(follow(ty));
}

View file

@ -438,6 +438,34 @@ TEST_CASE_FIXTURE(BuiltinsFixture, "compound_assign_mismatch_metatable")
CHECK("Type 'number' could not be converted into 'V2'" == toString(result.errors[0]));
}
TEST_CASE_FIXTURE(BuiltinsFixture, "overloaded_op_accept_structured_subtype")
{
ScopedFastFlag sff{"LuauIntersectedBinopOverloadFix", true};
CheckResult result = check(R"(
--!strict
type BaseType = typeof(setmetatable(
{},
({} :: any) :: {__add: (BaseType, BaseType) -> BaseType})
)
type SubType = BaseType & {extraField: string}
local function add1(x: BaseType, y: BaseType): BaseType
return x + y
end
local function add2(x: SubType, y: BaseType): BaseType
return x + y
end
local function add3(x: BaseType, y: SubType): BaseType
return x + y
end
local function add4(x: SubType, y: SubType): BaseType
return x + y
end
)");
LUAU_REQUIRE_ERROR_COUNT(0, result);
}
TEST_CASE_FIXTURE(Fixture, "CallOrOfFunctions")
{
CheckResult result = check(R"(