mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Check __call for class type vars
This commit is contained in:
parent
9f025a0d5f
commit
1e4a993f20
1 changed files with 19 additions and 14 deletions
|
@ -4135,26 +4135,31 @@ std::optional<WithPredicate<TypePackId>> TypeChecker::checkCallOverload(const Sc
|
||||||
|
|
||||||
std::vector<Location> metaArgLocations;
|
std::vector<Location> metaArgLocations;
|
||||||
|
|
||||||
// Might be a callable table
|
// Might be a callable table or class
|
||||||
|
std::optional<TypeId> callTy = std::nullopt;
|
||||||
if (const MetatableTypeVar* mttv = get<MetatableTypeVar>(fn))
|
if (const MetatableTypeVar* mttv = get<MetatableTypeVar>(fn))
|
||||||
{
|
{
|
||||||
if (std::optional<TypeId> ty = getIndexTypeFromType(scope, mttv->metatable, "__call", expr.func->location, /* addErrors= */ false))
|
callTy = getIndexTypeFromType(scope, mttv->metatable, "__call", expr.func->location, /* addErrors= */ false);
|
||||||
{
|
} else if (const ClassTypeVar* ctv = get<ClassTypeVar>(fn); ctv && ctv->metatable)
|
||||||
// Construct arguments with 'self' added in front
|
{
|
||||||
TypePackId metaCallArgPack = addTypePack(TypePackVar(TypePack{args->head, args->tail}));
|
callTy = getIndexTypeFromType(scope, *ctv->metatable, "__call", expr.func->location, /* addErrors= */ false);
|
||||||
|
}
|
||||||
|
|
||||||
TypePack* metaCallArgs = getMutable<TypePack>(metaCallArgPack);
|
if (callTy) {
|
||||||
metaCallArgs->head.insert(metaCallArgs->head.begin(), fn);
|
// Construct arguments with 'self' added in front
|
||||||
|
TypePackId metaCallArgPack = addTypePack(TypePackVar(TypePack{args->head, args->tail}));
|
||||||
|
|
||||||
metaArgLocations = *argLocations;
|
TypePack* metaCallArgs = getMutable<TypePack>(metaCallArgPack);
|
||||||
metaArgLocations.insert(metaArgLocations.begin(), expr.func->location);
|
metaCallArgs->head.insert(metaCallArgs->head.begin(), fn);
|
||||||
|
|
||||||
fn = instantiate(scope, *ty, expr.func->location);
|
metaArgLocations = *argLocations;
|
||||||
|
metaArgLocations.insert(metaArgLocations.begin(), expr.func->location);
|
||||||
|
|
||||||
argPack = metaCallArgPack;
|
fn = instantiate(scope, *callTy, expr.func->location);
|
||||||
args = metaCallArgs;
|
|
||||||
argLocations = &metaArgLocations;
|
argPack = metaCallArgPack;
|
||||||
}
|
args = metaCallArgs;
|
||||||
|
argLocations = &metaArgLocations;
|
||||||
}
|
}
|
||||||
|
|
||||||
const FunctionTypeVar* ftv = get<FunctionTypeVar>(fn);
|
const FunctionTypeVar* ftv = get<FunctionTypeVar>(fn);
|
||||||
|
|
Loading…
Add table
Reference in a new issue