Skip to content
Closed
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
53 changes: 32 additions & 21 deletions Analysis/src/Unifier2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,20 @@ bool Unifier2::unify(TypeId subTy, TypeId superTy)
auto subTable = getMutable<TableType>(subTy);
auto superTable = get<TableType>(superTy);

if (subAny && superAny)
if (subAny && superAny)
return true;
else if (subAny && superFn)
return unify(subAny, superFn);
else if (subFn && superAny)
return unify(subFn, superAny);
else if (subAny && superTable)
return unify(subAny, superTable);
else if (subTable && superAny)
return unify(subTable, superAny);

if (subAny) {
if (superFn)
return unify(subAny, superFn);
if (superTable)
return unify(subAny, superTable);
}
if (superAny) {
if (subFn)
return unify(subFn, superAny);
if (subTable)
return unify(subTable, superAny);
}
if (subTable && superTable)
{
// `boundTo` works like a bound type, and therefore we'd replace it
Expand All @@ -235,17 +238,25 @@ bool Unifier2::unify(TypeId subTy, TypeId superTy)

auto subMetatable = get<MetatableType>(subTy);
auto superMetatable = get<MetatableType>(superTy);
if (subMetatable && superMetatable)
return unify(subMetatable, superMetatable);
else if (FFlag::LuauUnifyMetatableWithAny && subMetatable && superAny)
return unify(subMetatable, superAny);
else if (FFlag::LuauUnifyMetatableWithAny && subAny && superMetatable)
return unify(subAny, superMetatable);
else if (subMetatable) // if we only have one metatable, unify with the inner table
return unify(subMetatable->table, superTy);
else if (superMetatable) // if we only have one metatable, unify with the inner table
return unify(subTy, superMetatable->table);


// Cache the flag value to avoid multiple checks
const bool flagEnabled = FFlag::LuauUnifyMetatableWithAny;

if (subMetatable) {
if (superMetatable)
return unify(subMetatable, superMetatable);
else if (flagEnabled && superAny)
return unify(subMetatable, superAny);
else
return unify(subMetatable->table, superTy); // if we only have one metatable, unify with the inner table
}
else if (superMetatable) {
if (flagEnabled && subAny)
return unify(subAny, superMetatable);
else
return unify(subTy, superMetatable->table); // if we only have one metatable, unify with the inner table
}

auto [subNegation, superNegation] = get2<NegationType, NegationType>(subTy, superTy);
if (subNegation && superNegation)
return unify(subNegation->ty, superNegation->ty);
Expand Down