mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Add failing test case for #1003 & fix error msg
This commit is contained in:
parent
0b2755f964
commit
de3c7f3348
2 changed files with 38 additions and 0 deletions
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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"(
|
||||
|
|
Loading…
Add table
Reference in a new issue