// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details #pragma once #include "Luau/Ast.h" #include "Luau/InsertionOrderedMap.h" #include "Luau/NotNull.h" #include "Luau/TypeFwd.h" #include "Luau/Location.h" #include "Luau/Error.h" #include "Luau/Subtyping.h" namespace Luau { struct BuiltinTypes; struct TypeArena; struct Scope; struct InternalErrorReporter; struct TypeCheckLimits; struct Subtyping; class Normalizer; struct OverloadResolver { enum Analysis { Ok, TypeIsNotAFunction, ArityMismatch, OverloadIsNonviable, // Arguments were incompatible with the overloads parameters but were otherwise compatible by arity }; OverloadResolver(NotNull builtinTypes, NotNull arena, NotNull normalizer, NotNull scope, NotNull reporter, NotNull limits, Location callLocation); NotNull builtinTypes; NotNull arena; NotNull normalizer; NotNull scope; NotNull ice; NotNull limits; Subtyping subtyping; Location callLoc; // Resolver results std::vector ok; std::vector nonFunctions; std::vector> arityMismatches; std::vector> nonviableOverloads; InsertionOrderedMap> resolution; std::pair selectOverload(TypeId ty, TypePackId args); void resolve(TypeId fnTy, const TypePack* args, AstExpr* selfExpr, const std::vector* argExprs); private: std::optional testIsSubtype(const Location& location, TypeId subTy, TypeId superTy); std::optional testIsSubtype(const Location& location, TypePackId subTy, TypePackId superTy); std::pair checkOverload( TypeId fnTy, const TypePack* args, AstExpr* fnLoc, const std::vector* argExprs, bool callMetamethodOk = true); static bool isLiteral(AstExpr* expr); LUAU_NOINLINE std::pair checkOverload_( TypeId fnTy, const FunctionType* fn, const TypePack* args, AstExpr* fnExpr, const std::vector* argExprs); size_t indexof(Analysis analysis); void add(Analysis analysis, TypeId ty, ErrorVec&& errors); }; struct SolveResult { enum OverloadCallResult { Ok, CodeTooComplex, OccursCheckFailed, NoMatchingOverload, }; OverloadCallResult result; std::optional typePackId; // nullopt if result != Ok TypeId overloadToUse = nullptr; TypeId inferredTy = nullptr; DenseHashMap> expandedFreeTypes{nullptr}; }; // Helper utility, presently used for binary operator type functions. // // Given a function and a set of arguments, select a suitable overload. SolveResult solveFunctionCall(NotNull arena, NotNull builtinTypes, NotNull normalizer, NotNull iceReporter, NotNull limits, NotNull scope, const Location& location, TypeId fn, TypePackId argsPack); } // namespace Luau