1 /* 2 * Copyright (c) 2021-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ES2PANDA_CHECKER_ETS_CHECKER_H 17 #define ES2PANDA_CHECKER_ETS_CHECKER_H 18 19 #include <cstddef> 20 #include <mutex> 21 22 #include "checker/checker.h" 23 24 #include "checker/types/globalTypesHolder.h" 25 #include "checker/types/ets/etsResizableArrayType.h" 26 #include "checker/types/ets/types.h" 27 #include "checker/resolveResult.h" 28 #include "ir/ts/tsInterfaceDeclaration.h" 29 #include "ir/visitor/AstVisitor.h" 30 #include "util/helpers.h" 31 32 namespace ark::es2panda::varbinder { 33 class VarBinder; 34 class Decl; 35 class EnumVariable; 36 class FunctionDecl; 37 class LocalVariable; 38 class Scope; 39 class Variable; 40 class ETSBinder; 41 class RecordTable; 42 class FunctionParamScope; 43 } // namespace ark::es2panda::varbinder 44 45 namespace ark::es2panda::evaluate { 46 class ScopedDebugInfoPlugin; 47 } // namespace ark::es2panda::evaluate 48 49 namespace ark::es2panda::checker { 50 51 struct Accessor { 52 bool isGetter {false}; 53 bool isSetter {false}; 54 bool isExternal {false}; 55 }; 56 57 struct PairHash { operatorPairHash58 size_t operator()(const std::pair<Type *, bool> &p) const 59 { 60 size_t hash1 = std::hash<Type *> {}(p.first); 61 size_t hash2 = std::hash<bool> {}(p.second); 62 return hash1 ^ (hash2 << 1ULL); 63 } 64 }; 65 using ComputedAbstracts = 66 ArenaUnorderedMap<ETSObjectType *, std::pair<ArenaVector<ETSFunctionType *>, ArenaUnorderedSet<ETSObjectType *>>>; 67 using ArrayMap = ArenaUnorderedMap<std::pair<Type *, bool>, ETSArrayType *, PairHash>; 68 using GlobalArraySignatureMap = ArenaUnorderedMap<const ETSArrayType *, Signature *>; 69 using DynamicCallIntrinsicsMap = ArenaUnorderedMap<Language, ArenaUnorderedMap<util::StringView, ir::ScriptFunction *>>; 70 using DynamicClassIntrinsicsMap = ArenaUnorderedMap<Language, ir::ClassDeclaration *>; 71 using DynamicLambdaObjectSignatureMap = ArenaUnorderedMap<std::string, Signature *>; 72 using FunctionalInterfaceMap = ArenaUnorderedMap<util::StringView, ETSObjectType *>; 73 using TypeMapping = ArenaUnorderedMap<Type const *, Type *>; 74 using DynamicCallNamesMap = ArenaMap<const ArenaVector<util::StringView>, uint32_t>; 75 using ConstraintCheckRecord = std::tuple<const ArenaVector<Type *> *, const Substitution *, lexer::SourcePosition>; 76 // can't use util::DiagnosticWithParams because std::optional can't contain references 77 using MaybeDiagnosticInfo = 78 std::optional<std::pair<const diagnostic::DiagnosticKind, const util::DiagnosticMessageParams>>; 79 using AstNodePtr = ir::AstNode *; 80 81 class ETSChecker final : public Checker { 82 public: 83 explicit ETSChecker(util::DiagnosticEngine &diagnosticEngine); 84 explicit ETSChecker(util::DiagnosticEngine &diagnosticEngine, ArenaAllocator *programAllocator); 85 86 ~ETSChecker() override = default; 87 88 NO_COPY_SEMANTIC(ETSChecker); 89 NO_MOVE_SEMANTIC(ETSChecker); 90 ETSType(const Type * const type)91 [[nodiscard]] static TypeFlag ETSType(const Type *const type) noexcept 92 { 93 return ETSChecker::TypeKind(type); 94 } 95 96 [[nodiscard]] static TypeFlag TypeKind(const Type *const type) noexcept; 97 98 Type *GlobalByteType() const; 99 Type *GlobalShortType() const; 100 Type *GlobalIntType() const; 101 Type *GlobalLongType() const; 102 Type *GlobalFloatType() const; 103 Type *GlobalDoubleType() const; 104 Type *GlobalCharType() const; 105 Type *GlobalETSBooleanType() const; 106 Type *GlobalVoidType() const; 107 Type *GlobalETSNullType() const; 108 Type *GlobalETSUndefinedType() const; 109 Type *GlobalETSAnyType() const; 110 Type *GlobalETSNeverType() const; 111 Type *GlobalETSStringLiteralType() const; 112 Type *GlobalETSBigIntType() const; 113 Type *GlobalWildcardType() const; 114 115 Type *GlobalByteBuiltinType() const; 116 Type *GlobalShortBuiltinType() const; 117 Type *GlobalIntBuiltinType() const; 118 Type *GlobalLongBuiltinType() const; 119 Type *GlobalFloatBuiltinType() const; 120 Type *GlobalDoubleBuiltinType() const; 121 Type *GlobalCharBuiltinType() const; 122 Type *GlobalETSBooleanBuiltinType() const; 123 124 ETSObjectType *GlobalETSObjectType() const; 125 ETSUnionType *GlobalETSUnionUndefinedNull() const; 126 ETSUnionType *GlobalETSUnionUndefinedNullObject() const; 127 ETSObjectType *GlobalBuiltinETSResizableArrayType() const; 128 ETSObjectType *GlobalBuiltinETSStringType() const; 129 ETSObjectType *GlobalBuiltinETSBigIntType() const; 130 ETSObjectType *GlobalBuiltinTypeType() const; 131 ETSObjectType *GlobalBuiltinExceptionType() const; 132 ETSObjectType *GlobalBuiltinErrorType() const; 133 ETSObjectType *GlobalStringBuilderBuiltinType() const; 134 ETSObjectType *GlobalBuiltinPromiseType() const; 135 ETSObjectType *GlobalBuiltinFunctionType() const; 136 ETSObjectType *GlobalBuiltinJSRuntimeType() const; 137 ETSObjectType *GlobalBuiltinJSValueType() const; 138 ETSObjectType *GlobalBuiltinBoxType(Type *contents); 139 140 ETSObjectType *GlobalBuiltinFunctionType(size_t nargs, bool hasRest) const; 141 ETSObjectType *GlobalBuiltinLambdaType(size_t nargs, bool hasRest) const; 142 size_t GlobalBuiltinFunctionTypeVariadicThreshold() const; 143 144 ETSObjectType *GlobalBuiltinTupleType(size_t nargs) const; 145 146 ETSObjectType *GlobalBuiltinDynamicType(Language lang) const; 147 148 GlobalArraySignatureMap &GlobalArrayTypes(); 149 const GlobalArraySignatureMap &GlobalArrayTypes() const; 150 151 Type *GlobalTypeError() const; 152 [[nodiscard]] Type *InvalidateType(ir::Typed<ir::AstNode> *node); 153 [[nodiscard]] Type *TypeError(ir::Typed<ir::AstNode> *node, const diagnostic::DiagnosticKind &diagKind, 154 const lexer::SourcePosition &at); 155 [[nodiscard]] Type *TypeError(ir::Typed<ir::AstNode> *node, const diagnostic::DiagnosticKind &diagKind, 156 const util::DiagnosticMessageParams &list, const lexer::SourcePosition &at); 157 [[nodiscard]] Type *TypeError(varbinder::Variable *var, const diagnostic::DiagnosticKind &diagKind, 158 const lexer::SourcePosition &at); 159 [[nodiscard]] Type *TypeError(varbinder::Variable *var, const diagnostic::DiagnosticKind &diagKind, 160 const util::DiagnosticMessageParams &list, const lexer::SourcePosition &at); 161 162 void InitializeBuiltins(varbinder::ETSBinder *varbinder); 163 void InitializeBuiltin(varbinder::Variable *var, const util::StringView &name); 164 bool StartChecker([[maybe_unused]] varbinder::VarBinder *varbinder, const util::Options &options) override; 165 Type *CheckTypeCached(ir::Expression *expr) override; ResolveStructuredTypeMembers(Type * type)166 void ResolveStructuredTypeMembers([[maybe_unused]] Type *type) override {}; 167 Type *GetTypeFromVariableDeclaration(varbinder::Variable *const var); 168 Type *GetTypeOfVariable([[maybe_unused]] varbinder::Variable *var) override; 169 Type *GuaranteedTypeForUncheckedCast(Type *base, Type *substituted); 170 Type *GuaranteedTypeForUncheckedCallReturn(Signature *sig); 171 Type *GuaranteedTypeForUncheckedPropertyAccess(varbinder::Variable *prop); 172 Type *GuaranteedTypeForUnionFieldAccess(ir::MemberExpression *memberExpression, ETSUnionType *etsUnionType); 173 IsETSChecker()174 [[nodiscard]] bool IsETSChecker() const noexcept override 175 { 176 return true; 177 } 178 179 // Object 180 void CheckObjectLiteralKeys(const ArenaVector<ir::Expression *> &properties); 181 Type *BuildBasicClassProperties(ir::ClassDefinition *classDef); 182 ETSObjectType *BuildAnonymousClassProperties(ir::ClassDefinition *classDef, ETSObjectType *superType); 183 Type *BuildBasicInterfaceProperties(ir::TSInterfaceDeclaration *interfaceDecl); 184 ETSObjectType *GetSuperType(ETSObjectType *type); 185 ArenaVector<ETSObjectType *> GetInterfaces(ETSObjectType *type); 186 void GetInterfacesOfClass(ETSObjectType *type); 187 void GetInterfacesOfInterface(ETSObjectType *type); 188 void ValidateImplementedInterface(ETSObjectType *type, Type *interface, std::unordered_set<Type *> *extendsSet, 189 const lexer::SourcePosition &pos); 190 void ResolveDeclaredMembersOfObject(const Type *type); 191 lexer::Number ExtractNumericValue(Type const *const indexType); 192 std::optional<std::size_t> GetTupleElementAccessValue(const Type *type); 193 bool ValidateArrayIndex(ir::Expression *expr, bool relaxed = false); 194 bool ValidateTupleIndex(const ETSTupleType *tuple, ir::MemberExpression *expr, bool reportError = true); 195 bool ValidateTupleIndexFromEtsObject(const ETSTupleType *const tuple, ir::MemberExpression *expr); 196 ETSObjectType *CheckThisOrSuperAccess(ir::Expression *node, ETSObjectType *classType, std::string_view msg); 197 void CreateTypeForClassOrInterfaceTypeParameters(ETSObjectType *type); 198 ETSTypeParameter *SetUpParameterType(ir::TSTypeParameter *param); 199 void GetInterfacesOfClass(ETSObjectType *type, ArenaVector<ETSObjectType *> &interfaces); 200 void CheckIfOverrideIsValidInInterface(ETSObjectType *classType, Signature *sig, Signature *sigFunc); 201 void CheckFunctionRedeclarationInInterface(ETSObjectType *classType, ArenaVector<Signature *> &similarSignatures, 202 Signature *sigFunc); 203 void ValidateAbstractMethodsToBeImplemented(ArenaVector<ETSFunctionType *> &abstractsToBeImplemented, 204 ETSObjectType *classType, 205 const std::vector<Signature *> &implementedSignatures); 206 void ApplyModifiersAndRemoveImplementedAbstracts(ArenaVector<ETSFunctionType *>::iterator &it, 207 ArenaVector<ETSFunctionType *> &abstractsToBeImplemented, 208 ETSObjectType *classType, bool &functionOverridden, 209 const Accessor &isGetSetExternal); 210 void ValidateAbstractSignature(ArenaVector<ETSFunctionType *>::iterator &it, 211 ArenaVector<ETSFunctionType *> &abstractsToBeImplemented, 212 const std::vector<Signature *> &implementedSignatures, bool &functionOverridden, 213 Accessor &isGetSetExternal); 214 void ValidateNonOverriddenFunction(ETSObjectType *classType, ArenaVector<ETSFunctionType *>::iterator &it, 215 ArenaVector<ETSFunctionType *> &abstractsToBeImplemented, 216 bool &functionOverridden, const Accessor &isGetSet); 217 void MaybeReportErrorsForOverridingValidation(ArenaVector<ETSFunctionType *> &abstractsToBeImplemented, 218 ETSObjectType *classType, const lexer::SourcePosition &pos, 219 bool reportError); 220 void ValidateOverriding(ETSObjectType *classType, const lexer::SourcePosition &pos); 221 void CheckInterfaceFunctions(ETSObjectType *classType); 222 void CollectImplementedMethodsFromInterfaces(ETSObjectType *classType, 223 std::vector<Signature *> *implementedSignatures, 224 const ArenaVector<ETSFunctionType *> &abstractsToBeImplemented); 225 void AddImplementedSignature(std::vector<Signature *> *implementedSignatures, varbinder::LocalVariable *function, 226 ETSFunctionType *it); 227 void CheckInnerClassMembers(const ETSObjectType *classType); 228 void CheckLocalClass(ir::ClassDefinition *classDef, CheckerStatus &checkerStatus); 229 void CheckClassDefinition(ir::ClassDefinition *classDef); 230 void CheckClassElement(ir::ClassDefinition *classDef); 231 void CheckClassAnnotations(ir::ClassDefinition *classDef); 232 void CheckInterfaceAnnotations(ir::TSInterfaceDeclaration *interfaceDecl); 233 void CheckConstructors(ir::ClassDefinition *classDef, ETSObjectType *classType); 234 void FindAssignment(const ir::AstNode *node, const varbinder::LocalVariable *classVar, bool &initialized); 235 void FindAssignments(const ir::AstNode *node, const varbinder::LocalVariable *classVar, bool &initialized); 236 void CheckConstFields(const ETSObjectType *classType); 237 void CheckConstFieldInitialized(const ETSObjectType *classType, varbinder::LocalVariable *classVar); 238 void CheckConstFieldInitialized(const Signature *signature, varbinder::LocalVariable *classVar); 239 void ComputeAbstractsFromInterface(ETSObjectType *interfaceType); 240 ArenaVector<ETSFunctionType *> &GetAbstractsForClass(ETSObjectType *classType); 241 std::vector<Signature *> CollectAbstractSignaturesFromObject(const ETSObjectType *objType); 242 void CreateFunctionTypesFromAbstracts(const std::vector<Signature *> &abstracts, 243 ArenaVector<ETSFunctionType *> *target); 244 void CheckCyclicConstructorCall(Signature *signature); 245 std::vector<ResolveResult *> ResolveMemberReference(const ir::MemberExpression *memberExpr, 246 const ETSObjectType *target); 247 void WarnForEndlessLoopInGetterSetter(const ir::MemberExpression *const memberExpr); 248 varbinder::Variable *GetExtensionFuncVarInGlobalFunction(const ir::MemberExpression *const memberExpr); 249 varbinder::Variable *GetExtensionFuncVarInGlobalField(const ir::MemberExpression *const memberExpr); 250 varbinder::Variable *GetExtensionFuncVarInFunctionScope(const ir::MemberExpression *const memberExpr); 251 varbinder::Variable *ResolveInstanceExtension(const ir::MemberExpression *memberExpr); 252 void CheckImplicitSuper(ETSObjectType *classType, Signature *ctorSig); 253 void CheckThisOrSuperCallInConstructor(ETSObjectType *classType, Signature *ctorSig); 254 void CheckExpressionsInConstructor(const ArenaVector<const ir::Expression *> &arguments); 255 ArenaVector<const ir::Expression *> CheckMemberOrCallOrObjectExpressionInConstructor(const ir::Expression *arg); 256 void CheckValidInheritance(ETSObjectType *classType, ir::ClassDefinition *classDef); 257 void CheckProperties(ETSObjectType *classType, ir::ClassDefinition *classDef, varbinder::LocalVariable *it, 258 varbinder::LocalVariable *found, ETSObjectType *interfaceFound); 259 void CheckReadonlyClassPropertyInImplementedInterface(ETSObjectType *classType, varbinder::LocalVariable *field); 260 void TransformProperties(ETSObjectType *classType); 261 void CheckGetterSetterProperties(ETSObjectType *classType); 262 void AddElementsToModuleObject(ETSObjectType *moduleObj, const util::StringView &str); ComputeApparentType(Type * type)263 void ComputeApparentType(Type *type) 264 { 265 // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) 266 [[maybe_unused]] auto x = GetApparentType(type); 267 } 268 [[nodiscard]] Type *GetApparentType(Type *type); 269 [[nodiscard]] Type const *GetApparentType(Type const *type) const; 270 ETSObjectType *GetClosestCommonAncestor(ETSObjectType *source, ETSObjectType *target); 271 bool HasETSFunctionType(ir::TypeNode *typeAnnotation); 272 273 void VariableTypeFromInitializer(varbinder::Variable *variable, Type *annotationType, Type *initType); 274 275 // Type creation 276 ByteType *CreateByteType(int8_t value); 277 ETSBooleanType *CreateETSBooleanType(bool value); 278 DoubleType *CreateDoubleType(double value); 279 FloatType *CreateFloatType(float value); 280 IntType *CreateIntType(int32_t value); 281 LongType *CreateLongType(int64_t value); 282 ShortType *CreateShortType(int16_t value); 283 CharType *CreateCharType(char16_t value); 284 ETSBigIntType *CreateETSBigIntLiteralType(util::StringView value); 285 ETSStringType *CreateETSStringLiteralType(util::StringView value); 286 ETSResizableArrayType *CreateETSMultiDimResizableArrayType(Type *element, size_t dimSize); 287 ETSResizableArrayType *CreateETSResizableArrayType(Type *element); 288 ETSArrayType *CreateETSArrayType(Type *elementType, bool isCachePolluting = false); 289 Type *CreateETSUnionType(Span<Type *const> constituentTypes); 290 template <size_t N> CreateETSUnionType(Type * const (& arr)[N])291 Type *CreateETSUnionType(Type *const (&arr)[N]) // NOLINT(modernize-avoid-c-arrays) 292 { 293 return CreateETSUnionType(Span(arr)); 294 } CreateETSUnionType(ArenaVector<Type * > && constituentTypes)295 Type *CreateETSUnionType(ArenaVector<Type *> &&constituentTypes) 296 { 297 return CreateETSUnionType(Span<Type *const>(constituentTypes)); 298 } 299 Type *CreateUnionFromKeyofType(ETSObjectType *const type); 300 void ProcessTypeMembers(ETSObjectType *type, ArenaVector<Type *> &literals); 301 ETSAsyncFuncReturnType *CreateETSAsyncFuncReturnTypeFromPromiseType(ETSObjectType *promiseType); 302 ETSAsyncFuncReturnType *CreateETSAsyncFuncReturnTypeFromBaseType(Type *baseType); 303 ETSTypeAliasType *CreateETSTypeAliasType(util::StringView name, const ir::AstNode *declNode, 304 bool isRecursive = false); 305 ETSFunctionType *CreateETSArrowType(Signature *signature); 306 ETSFunctionType *CreateETSMethodType(util::StringView name, ArenaVector<Signature *> &&signatures); 307 ETSFunctionType *CreateETSDynamicArrowType(Signature *signature, Language lang); 308 ETSFunctionType *CreateETSDynamicMethodType(util::StringView name, ArenaVector<Signature *> &&signatures, 309 Language lang); 310 ETSExtensionFuncHelperType *CreateETSExtensionFuncHelperType(ETSFunctionType *classMethodType, 311 ETSFunctionType *extensionFunctionType); 312 void AddThisReturnTypeFlagForInterfaceInvoke(ETSObjectType *interface); 313 ETSTypeParameter *CreateTypeParameter(); 314 ETSObjectType *CreateETSObjectType(ir::AstNode *declNode, ETSObjectFlags flags); 315 ETSObjectType *CreateETSObjectTypeOrBuiltin(ir::AstNode *declNode, ETSObjectFlags flags); 316 std::tuple<util::StringView, SignatureInfo *> CreateBuiltinArraySignatureInfo(const ETSArrayType *arrayType, 317 size_t dim); 318 Signature *CreateBuiltinArraySignature(const ETSArrayType *arrayType, size_t dim); 319 IntType *CreateIntTypeFromType(Type *type); 320 std::tuple<Language, bool> CheckForDynamicLang(ir::AstNode *declNode, util::StringView assemblerName); 321 ETSObjectType *CreatePromiseOf(Type *type); 322 323 Signature *CreateSignature(SignatureInfo *info, Type *returnType, ir::ScriptFunction *func); 324 Signature *CreateSignature(SignatureInfo *info, Type *returnType, ir::ScriptFunctionFlags sff, bool hasReceiver); 325 SignatureInfo *CreateSignatureInfo(); 326 327 // Arithmetic 328 Type *NegateNumericType(Type *type, ir::Expression *node); 329 bool CheckBinaryOperatorForBigInt(Type *left, Type *right, lexer::TokenType op); 330 [[nodiscard]] bool CheckBinaryPlusMultDivOperandsForUnionType(const Type *leftType, const Type *rightType, 331 const ir::Expression *left, 332 const ir::Expression *right); 333 // CC-OFFNXT(G.FUN.01-CPP) solid logic 334 std::tuple<Type *, Type *> CheckBinaryOperator(ir::Expression *left, ir::Expression *right, ir::Expression *expr, 335 lexer::TokenType operationType, lexer::SourcePosition pos, 336 bool forcePromotion = false); 337 std::tuple<Type *, Type *> CheckArithmeticOperations( 338 ir::Expression *expr, 339 std::tuple<ir::Expression *, ir::Expression *, lexer::TokenType, lexer::SourcePosition> op, bool isEqualOp, 340 std::tuple<checker::Type *, checker::Type *, Type *, Type *> types); 341 checker::Type *CheckBinaryOperatorMulDivMod( 342 std::tuple<ir::Expression *, ir::Expression *, lexer::TokenType, lexer::SourcePosition> op, bool isEqualOp, 343 std::tuple<checker::Type *, checker::Type *, Type *, Type *> types); 344 checker::Type *CheckBinaryOperatorForIntEnums(const checker::Type *const leftType, 345 const checker::Type *const rightType); 346 checker::Type *CheckBinaryBitwiseOperatorForIntEnums(const checker::Type *const leftType, 347 const checker::Type *const rightType); 348 checker::Type *CheckBinaryOperatorPlusForEnums(const checker::Type *const leftType, 349 const checker::Type *const rightType); 350 checker::Type *CheckBinaryOperatorPlus( 351 std::tuple<ir::Expression *, ir::Expression *, lexer::TokenType, lexer::SourcePosition> op, bool isEqualOp, 352 std::tuple<checker::Type *, checker::Type *, Type *, Type *> types); 353 checker::Type *CheckBinaryOperatorShift( 354 std::tuple<ir::Expression *, ir::Expression *, lexer::TokenType, lexer::SourcePosition> op, bool isEqualOp, 355 std::tuple<checker::Type *, checker::Type *, Type *, Type *> types); 356 checker::Type *CheckBinaryOperatorBitwise( 357 std::tuple<ir::Expression *, ir::Expression *, lexer::TokenType, lexer::SourcePosition> op, bool isEqualOp, 358 std::tuple<checker::Type *, checker::Type *, Type *, Type *> types); 359 // CC-OFFNXT(G.FUN.01-CPP) solid logic 360 checker::Type *CheckBinaryOperatorLogical(ir::Expression *left, ir::Expression *right, ir::BinaryExpression *expr, 361 checker::Type *leftType, checker::Type *rightType, Type *unboxedL, 362 Type *unboxedR); 363 std::tuple<Type *, Type *> CheckBinaryOperatorStrictEqual(ir::Expression *left, lexer::TokenType operationType, 364 lexer::SourcePosition pos, checker::Type *leftType, 365 checker::Type *rightType); 366 // CC-OFFNXT(G.FUN.01-CPP) solid logic 367 std::tuple<Type *, Type *> CheckBinaryOperatorLessGreater(ir::Expression *left, ir::Expression *right, 368 lexer::TokenType operationType, lexer::SourcePosition pos, 369 bool isEqualOp, checker::Type *leftType, 370 checker::Type *rightType, Type *unboxedL, Type *unboxedR); 371 std::tuple<Type *, Type *> CheckBinaryOperatorInstanceOf(lexer::SourcePosition pos, checker::Type *leftType, 372 checker::Type *rightType); 373 checker::Type *CheckBinaryOperatorNullishCoalescing(ir::Expression *left, ir::Expression *right, 374 lexer::SourcePosition pos); 375 bool AdjustNumberLiteralType(ir::NumberLiteral *literal, Type *literalType, Type *otherType); 376 377 Type *HandleArithmeticOperationOnTypes(Type *left, Type *right, lexer::TokenType operationType); 378 Type *HandleBitwiseOperationOnTypes(Type *left, Type *right, lexer::TokenType operationType); 379 void FlagExpressionWithUnboxing(Type *type, Type *unboxedType, ir::Expression *typeExpression); 380 template <typename ValueType> 381 Type *PerformArithmeticOperationOnTypes(Type *left, Type *right, lexer::TokenType operationType); 382 383 Type *HandleRelationOperationOnTypes(Type *left, Type *right, lexer::TokenType operationType); 384 template <typename TargetType> 385 Type *PerformRelationOperationOnTypes(Type *left, Type *right, lexer::TokenType operationType); 386 387 // Function 388 bool NeedTypeInference(const ir::ScriptFunction *lambda); 389 std::vector<bool> FindTypeInferenceArguments(const ArenaVector<ir::Expression *> &arguments); 390 void InferTypesForLambda(ir::ScriptFunction *lambda, ir::ETSFunctionType *calleeType, 391 Signature *maybeSubstitutedFunctionSig = nullptr); 392 void InferTypesForLambda(ir::ScriptFunction *lambda, Signature *signature); 393 void TryInferTypeForLambdaTypeAlias(ir::ArrowFunctionExpression *expr, ETSFunctionType *calleeType); 394 bool ResolveLambdaArgumentType(Signature *signature, ir::Expression *argument, size_t paramPosition, 395 size_t argumentPosition, TypeRelationFlag resolutionFlags); 396 bool TrailingLambdaTypeInference(Signature *signature, const ArenaVector<ir::Expression *> &arguments); 397 bool TypeInference(Signature *signature, const ArenaVector<ir::Expression *> &arguments, 398 TypeRelationFlag flags = TypeRelationFlag::NONE); 399 bool CheckLambdaTypeAnnotation(ir::ETSParameterExpression *param, ir::ArrowFunctionExpression *arrowFuncExpr, 400 Type *parameterType, TypeRelationFlag flags); 401 bool CheckLambdaInfer(ir::AstNode *typeAnnotation, ir::ArrowFunctionExpression *arrowFuncExpr, 402 Type *const subParameterType); 403 bool CheckLambdaAssignable(ir::Expression *param, ir::ScriptFunction *lambda); 404 bool CheckLambdaAssignableUnion(ir::AstNode *typeAnn, ir::ScriptFunction *lambda); 405 bool IsCompatibleTypeArgument(ETSTypeParameter *typeParam, Type *typeArgument, const Substitution *substitution); 406 NewSubstitution()407 Substitution *NewSubstitution() 408 { 409 return ProgramAllocator()->New<Substitution>(ProgramAllocator()->Adapter()); 410 } 411 CopySubstitution(const Substitution * src)412 Substitution *CopySubstitution(const Substitution *src) 413 { 414 return ProgramAllocator()->New<Substitution>(*src); 415 } 416 bool ValidateTypeSubstitution(const ArenaVector<Type *> &typeParams, Type *ctype, Type *argumentType, 417 Substitution *substitution); 418 bool ProcessUntypedParameter(ir::AstNode *declNode, size_t paramIndex, Signature *paramSig, Signature *argSig, 419 Substitution *substitution); 420 421 void EmplaceSubstituted(Substitution *substitution, ETSTypeParameter *tparam, Type *typeArg); 422 [[nodiscard]] bool EnhanceSubstitutionForType(const ArenaVector<Type *> &typeParams, Type *paramType, 423 Type *argumentType, Substitution *substitution); 424 [[nodiscard]] bool EnhanceSubstitutionForReadonly(const ArenaVector<Type *> &typeParams, ETSReadonlyType *paramType, 425 Type *argumentType, Substitution *substitution); 426 [[nodiscard]] bool EnhanceSubstitutionForObject(const ArenaVector<Type *> &typeParams, ETSObjectType *paramType, 427 Type *argumentType, Substitution *substitution); 428 [[nodiscard]] bool EnhanceSubstitutionForFunction(const ArenaVector<Type *> &typeParams, ETSFunctionType *paramType, 429 Type *argumentType, Substitution *substitution); 430 [[nodiscard]] bool EnhanceSubstitutionForUnion(const ArenaVector<Type *> &typeParams, ETSUnionType *paramUn, 431 Type *argumentType, Substitution *substitution); 432 [[nodiscard]] bool EnhanceSubstitutionForArray(const ArenaVector<Type *> &typeParams, ETSArrayType *paramType, 433 Type *argumentType, Substitution *substitution); 434 [[nodiscard]] bool EnhanceSubstitutionForResizableArray(const ArenaVector<Type *> &typeParams, 435 ETSResizableArrayType *paramType, Type *argumentType, 436 Substitution *substitution); 437 std::pair<ArenaVector<Type *>, bool> CreateUnconstrainedTypeParameters( 438 ir::TSTypeParameterDeclaration const *typeParams); 439 void AssignTypeParameterConstraints(ir::TSTypeParameterDeclaration const *typeParams); 440 Signature *ValidateParameterlessConstructor(Signature *signature, const lexer::SourcePosition &pos, 441 bool throwError); 442 Signature *CollectParameterlessConstructor(ArenaVector<Signature *> &signatures, const lexer::SourcePosition &pos); 443 Signature *ValidateSignature( 444 std::tuple<Signature *, const ir::TSTypeParameterInstantiation *, TypeRelationFlag> info, 445 const ArenaVector<ir::Expression *> &arguments, const lexer::SourcePosition &pos, 446 const std::vector<bool> &argTypeInferenceRequired, const bool unique); 447 bool ValidateSignatureRequiredParams(Signature *substitutedSig, const ArenaVector<ir::Expression *> &arguments, 448 TypeRelationFlag flags, const std::vector<bool> &argTypeInferenceRequired, 449 bool reportError); 450 bool ValidateSignatureInvocationContext(Signature *substitutedSig, ir::Expression *argument, std::size_t index, 451 TypeRelationFlag flags); 452 bool CheckOptionalLambdaFunction(ir::Expression *argument, Signature *substitutedSig, std::size_t index); 453 bool ValidateArgumentAsIdentifier(const ir::Identifier *identifier); 454 bool IsValidRestArgument(ir::Expression *argument, Signature *substitutedSig, TypeRelationFlag flags, 455 std::size_t index); 456 bool ValidateSignatureRestParams(Signature *substitutedSig, const ArenaVector<ir::Expression *> &arguments, 457 TypeRelationFlag flags, bool reportError, bool unique); 458 void ThrowSignatureMismatch(ArenaVector<Signature *> &signatures, const ArenaVector<ir::Expression *> &arguments, 459 const lexer::SourcePosition &pos, std::string_view signatureKind); 460 // CC-OFFNXT(G.FUN.01-CPP) solid logic 461 Signature *ValidateSignatures(ArenaVector<Signature *> &signatures, 462 const ir::TSTypeParameterInstantiation *typeArguments, 463 const ArenaVector<ir::Expression *> &arguments, const lexer::SourcePosition &pos, 464 std::string_view signatureKind, 465 TypeRelationFlag resolveFlags = TypeRelationFlag::NONE); 466 Signature *FindMostSpecificSignature(const ArenaVector<Signature *> &signatures, 467 const ArenaMultiMap<size_t, Signature *> &bestSignaturesForParameter, 468 size_t paramCount); 469 void SearchAmongMostSpecificTypes(Type *&mostSpecificType, Signature *&prevSig, 470 std::tuple<const lexer::SourcePosition &, size_t, Signature *> info, 471 bool lookForClassType); 472 void CollectSuitableSignaturesForTypeInference(size_t paramIdx, ArenaVector<Signature *> &signatures, 473 ArenaMultiMap<size_t, Signature *> &bestSignaturesForParameter, 474 const ArenaVector<ir::Expression *> &arguments); 475 ArenaMultiMap<size_t, Signature *> GetSuitableSignaturesForParameter( 476 const std::vector<bool> &argTypeInferenceRequired, size_t paramCount, ArenaVector<Signature *> &signatures, 477 const ArenaVector<ir::Expression *> &arguments, const lexer::SourcePosition &pos); 478 Signature *ChooseMostSpecificSignature(ArenaVector<Signature *> &signatures, 479 const std::vector<bool> &argTypeInferenceRequired, 480 const ArenaVector<ir::Expression *> &arguments, 481 const lexer::SourcePosition &pos, size_t argumentsSize = ULONG_MAX); 482 Signature *ResolvePotentialTrailingLambdaWithReceiver(ir::CallExpression *callExpr, 483 ArenaVector<Signature *> const &signatures, 484 ArenaVector<ir::Expression *> &arguments); 485 Signature *ResolveCallExpressionAndTrailingLambda(ArenaVector<Signature *> &signatures, 486 ir::CallExpression *callExpr, const lexer::SourcePosition &pos, 487 TypeRelationFlag reportFlag = TypeRelationFlag::NONE); 488 void UpdateDeclarationFromSignature(ir::CallExpression *expr, checker::Signature *signature); 489 Signature *ResolveConstructExpression(ETSObjectType *type, const ArenaVector<ir::Expression *> &arguments, 490 const lexer::SourcePosition &pos); 491 void CheckObjectLiteralArguments(Signature *sig, ArenaVector<ir::Expression *> const &arguments); 492 493 Signature *ComposeSignature(ir::ScriptFunction *func, SignatureInfo *signatureInfo, Type *returnType, 494 varbinder::Variable *nameVar); 495 Type *ComposeReturnType(ir::TypeNode *typeAnnotation, bool isAsync); 496 SignatureInfo *ComposeSignatureInfo(ir::TSTypeParameterDeclaration *typeParams, 497 ArenaVector<ir::Expression *> const ¶ms); 498 void ValidateMainSignature(ir::ScriptFunction *func); 499 void BuildFunctionSignature(ir::ScriptFunction *func, bool isConstructSig = false); 500 ETSFunctionType *BuildMethodType(ir::ScriptFunction *func); 501 Type *BuildMethodSignature(ir::MethodDefinition *method); 502 Signature *CheckEveryAbstractSignatureIsOverridden(ETSFunctionType *target, ETSFunctionType *source); 503 static Signature *GetSignatureFromMethodDefinition(const ir::MethodDefinition *methodDef); 504 bool CheckIdenticalOverloads(ETSFunctionType *func, ETSFunctionType *overload, 505 const ir::MethodDefinition *currentFunc, bool omitSameAsm = false); 506 static bool CmpAssemblerTypesWithRank(Signature const *const sig1, Signature const *const sig2) noexcept; 507 static bool HasSameAssemblySignature(Signature const *const sig1, Signature const *const sig2) noexcept; 508 static bool HasSameAssemblySignatures(ETSFunctionType const *const func1, 509 ETSFunctionType const *const func2) noexcept; 510 511 Signature *AdjustForTypeParameters(Signature *source, Signature *target); 512 void ReportOverrideError(Signature *signature, Signature *overriddenSignature, const OverrideErrorCode &errorCode); 513 void CheckOverride(Signature *signature); 514 bool CheckOverride(Signature *signature, ETSObjectType *site); 515 OverrideErrorCode CheckOverride(Signature *signature, Signature *other); 516 bool IsMethodOverridesOther(Signature *base, Signature *derived); 517 bool IsOverridableIn(Signature *signature); 518 [[nodiscard]] bool AreOverrideCompatible(Signature *s1, Signature *s2); 519 [[nodiscard]] bool IsReturnTypeSubstitutable(Signature *s1, Signature *s2); 520 bool NeedToVerifySignatureVisibility(Signature *signature, const lexer::SourcePosition &pos); 521 void ValidateSignatureAccessibility(ETSObjectType *callee, Signature *signature, const lexer::SourcePosition &pos, 522 const MaybeDiagnosticInfo &maybeErrorInfo = std::nullopt); 523 void CheckCapturedVariables(); 524 void CheckCapturedVariableInSubnodes(ir::AstNode *node, varbinder::Variable *var); 525 void CheckCapturedVariable(ir::AstNode *node, varbinder::Variable *var); 526 527 // CC-OFFNXT(G.FUN.01-CPP) solid logic 528 ir::MethodDefinition *CreateMethod(const util::StringView &name, ir::ModifierFlags modifiers, 529 ir::ScriptFunctionFlags flags, ArenaVector<ir::Expression *> &¶ms, 530 varbinder::FunctionParamScope *paramScope, ir::TypeNode *returnType, 531 ir::AstNode *body); 532 varbinder::FunctionParamScope *CopyParams( 533 const ArenaVector<ir::Expression *> ¶ms, ArenaVector<ir::Expression *> &outParams, 534 ArenaUnorderedMap<varbinder::Variable *, varbinder::Variable *> *paramVarMap); 535 void ReplaceScope(ir::AstNode *root, ir::AstNode *oldNode, varbinder::Scope *newScope); 536 537 // Helpers 538 static std::string GetAsyncImplName(const util::StringView &name); 539 static std::string GetAsyncImplName(ir::MethodDefinition *asyncMethod); 540 static bool IsAsyncImplMethod(ir::MethodDefinition const *method); 541 std::vector<util::StringView> GetNameForSynteticObjectType(const util::StringView &source); 542 template <checker::PropertyType TYPE> 543 void BindingsModuleObjectAddProperty(checker::ETSObjectType *moduleObjType, ir::ETSImportDeclaration *importDecl, 544 const varbinder::Scope::VariableMap &bindings, 545 const util::StringView &importPath); 546 util::StringView FindPropNameForNamespaceImport(const util::StringView &originalName, 547 const util::StringView &importPath); 548 void SetPropertiesForModuleObject(checker::ETSObjectType *moduleObjType, const util::StringView &importPath, 549 ir::ETSImportDeclaration *importDecl = nullptr); 550 void SetrModuleObjectTsType(ir::Identifier *local, checker::ETSObjectType *moduleObjType); 551 Type *GetReferencedTypeFromBase(Type *baseType, ir::Expression *name); 552 Type *GetReferencedTypeBase(ir::Expression *name); 553 Type *ResolveReferencedType(varbinder::LocalVariable *refVar, const ir::Expression *name); 554 Type *GetTypeFromInterfaceReference(varbinder::Variable *var); 555 Type *GetTypeFromTypeAliasReference(varbinder::Variable *var); 556 Type *GetTypeFromClassReference(varbinder::Variable *var); 557 void ValidateGenericTypeAliasForClonedNode(ir::TSTypeAliasDeclaration *typeAliasNode, 558 const ir::TSTypeParameterInstantiation *exactTypeParams); 559 Type *HandleTypeAlias(ir::Expression *name, const ir::TSTypeParameterInstantiation *typeParams, 560 ir::TSTypeAliasDeclaration *const typeAliasNode); 561 bool CheckMinimumTypeArgsPresent(const ir::TSTypeAliasDeclaration *typeAliasNode, 562 const ir::TSTypeParameterInstantiation *typeParams); 563 static ir::TypeNode *ResolveTypeNodeForTypeArg(const ir::TSTypeAliasDeclaration *typeAliasNode, 564 const ir::TSTypeParameterInstantiation *typeParams, size_t idx); 565 Type *GetTypeFromTypeParameterReference(varbinder::LocalVariable *var, const lexer::SourcePosition &pos); 566 Type *GetNonConstantType(Type *type); 567 checker::Type *GetElementTypeOfArray(checker::Type *type); 568 const checker::Type *GetElementTypeOfArray(const checker::Type *type) const; 569 bool IsNullLikeOrVoidExpression(const ir::Expression *expr) const; 570 bool IsConstantExpression(ir::Expression *expr, Type *type); 571 void ValidateUnaryOperatorOperand(varbinder::Variable *variable); 572 bool ValidateAnnotationPropertyType(checker::Type *tsType); 573 void ProcessRequiredFields(ArenaUnorderedMap<util::StringView, ir::ClassProperty *> &fieldMap, 574 ir::AnnotationUsage *st, ETSChecker *checker) const; 575 void CheckFunctionSignatureAnnotations(const ArenaVector<ir::Expression *> ¶ms, 576 ir::TSTypeParameterDeclaration *typeParams, 577 ir::TypeNode *returnTypeAnnotation); 578 bool CheckAndLogInvalidThisUsage(const ir::TypeNode *type, const diagnostic::DiagnosticKind &diagnostic); 579 bool IsFixedArray(ir::ETSTypeReferencePart *part); 580 void ValidateThisUsage(const ir::TypeNode *returnTypeAnnotation); 581 void CheckAnnotations(const ArenaVector<ir::AnnotationUsage *> &annotations); 582 void CheckAmbientAnnotation(ir::AnnotationDeclaration *annoImpl, ir::AnnotationDeclaration *annoDecl); 583 bool CheckAmbientAnnotationFieldInitializerValue(ir::Expression *init, ir::Expression *expected); 584 bool CheckAmbientAnnotationFieldInitializer(ir::Expression *init, ir::Expression *expected); 585 void CheckAnnotationRetention(ir::AnnotationUsage *anno); 586 void HandleAnnotationRetention(ir::AnnotationUsage *anno, ir::AnnotationDeclaration *annoDecl); 587 void CheckStandardAnnotation(ir::AnnotationUsage *anno); 588 void CheckAnnotationPropertyType(ir::ClassProperty *property); 589 void CheckSinglePropertyAnnotation(ir::AnnotationUsage *st, ir::AnnotationDeclaration *annoDecl); 590 void CheckMultiplePropertiesAnnotation(ir::AnnotationUsage *st, util::StringView const &baseName, 591 ArenaUnorderedMap<util::StringView, ir::ClassProperty *> &fieldMap); 592 void InferAliasLambdaType(ir::TypeNode *localTypeAnnotation, ir::ArrowFunctionExpression *init); 593 checker::Type *ApplyConditionalOperatorPromotion(checker::ETSChecker *checker, checker::Type *unboxedL, 594 checker::Type *unboxedR); 595 Type *ApplyUnaryOperatorPromotion(Type *type, bool createConst = true, bool doPromotion = true, 596 bool isCondExpr = false); 597 Type *HandleBooleanLogicalOperators(Type *leftType, Type *rightType, lexer::TokenType tokenType); 598 599 bool HandleLogicalPotentialResult(ir::Expression *left, ir::Expression *right, ir::BinaryExpression *expr, 600 checker::Type *leftType); 601 602 checker::Type *FixOptionalVariableType(varbinder::Variable *const bindingVar, ir::ModifierFlags flags, 603 ir::Expression *init); 604 void CheckEnumType(ir::Expression *init, checker::Type *initType, const util::StringView &varName); 605 checker::Type *CheckVariableDeclaration(ir::Identifier *ident, ir::TypeNode *typeAnnotation, ir::Expression *init, 606 ir::ModifierFlags flags); 607 void CheckTruthinessOfType(ir::Expression *expr); 608 609 bool CheckNonNullish(ir::Expression const *expr); 610 Type *GetNonNullishType(Type *type); 611 Type *RemoveNullType(Type *type); 612 Type *RemoveUndefinedType(Type *type); 613 std::pair<Type *, Type *> RemoveNullishTypes(Type *type); 614 615 void ConcatConstantString(util::UString &target, Type *type); 616 Type *HandleStringConcatenation(Type *leftType, Type *rightType); 617 Type *ResolveIdentifier(ir::Identifier *ident); 618 ETSFunctionType *FindFunctionInVectorGivenByName(util::StringView name, ArenaVector<ETSFunctionType *> &list); 619 void MergeComputedAbstracts(ArenaVector<ETSFunctionType *> &merged, ArenaVector<ETSFunctionType *> ¤t); 620 void MergeSignatures(ETSFunctionType *target, ETSFunctionType *source); 621 ir::AstNode *FindAncestorGivenByType(ir::AstNode *node, ir::AstNodeType type, const ir::AstNode *endNode = nullptr); 622 util::StringView GetContainingObjectNameFromSignature(Signature *signature); 623 bool IsFunctionContainsSignature(ETSFunctionType *funcType, Signature *signature); 624 bool CheckFunctionContainsClashingSignature(const ETSFunctionType *funcType, Signature *signature); IsReferenceType(const Type * type)625 static bool IsReferenceType(const Type *type) 626 { 627 return type->IsETSReferenceType(); 628 } 629 void ValidatePropertyAccess(varbinder::Variable *var, ETSObjectType *obj, const lexer::SourcePosition &pos); 630 varbinder::VariableFlags GetAccessFlagFromNode(const ir::AstNode *node); 631 Type *CheckSwitchDiscriminant(ir::Expression *discriminant); 632 Type *MaybeUnboxInRelation(Type *objectType); 633 Type *MaybeUnboxConditionalInRelation(Type *objectType); 634 Type *MaybeBoxInRelation(Type *objectType); 635 void AddBoxingUnboxingFlagsToNode(ir::AstNode *node, Type *boxingUnboxingType); 636 ir::BoxingUnboxingFlags GetBoxingFlag(Type *boxingType); 637 ir::BoxingUnboxingFlags GetUnboxingFlag(Type const *unboxingType) const; 638 Type *MaybeBoxExpression(ir::Expression *expr); 639 Type *MaybeUnboxExpression(ir::Expression *expr); 640 Type *MaybeBoxType(Type *type) const; 641 Type *MaybeUnboxType(Type *type) const; 642 Type const *MaybeBoxType(Type const *type) const; 643 Type const *MaybeUnboxType(Type const *type) const; 644 void CheckForSameSwitchCases(ArenaVector<ir::SwitchCaseStatement *> const &cases); 645 std::string GetStringFromIdentifierValue(checker::Type *caseType) const; 646 bool CompareIdentifiersValuesAreDifferent(ir::Expression *compareValue, const std::string &caseValue); 647 void CheckIdentifierSwitchCase(ir::Expression *currentCase, ir::Expression *compareCase, 648 const lexer::SourcePosition &pos); 649 std::string GetStringFromLiteral(ir::Expression *caseTest) const; 650 varbinder::Variable *FindVariableInFunctionScope(util::StringView name); 651 std::pair<varbinder::Variable *, const ETSObjectType *> FindVariableInClassOrEnclosing( 652 util::StringView name, const ETSObjectType *classType); 653 varbinder::Variable *FindVariableInGlobal(const ir::Identifier *identifier); 654 varbinder::Variable *ExtraCheckForResolvedError(ir::Identifier *ident); 655 void ValidateResolvedIdentifier(ir::Identifier *ident); 656 static bool IsVariableStatic(const varbinder::Variable *var); 657 static bool IsVariableGetterSetter(const varbinder::Variable *var); 658 static bool IsVariableExtensionAccessor(const varbinder::Variable *var); 659 bool IsSameDeclarationType(varbinder::LocalVariable *target, varbinder::LocalVariable *compare); 660 void SaveCapturedVariable(varbinder::Variable *var, ir::Identifier *ident); 661 bool SaveCapturedVariableInLocalClass(varbinder::Variable *var, ir::Identifier *ident); 662 void MaybeAddBoxingFlagInRelation(TypeRelation *relation, Type *target); 663 void MaybeAddUnboxingFlagInRelation(TypeRelation *relation, Type *source, Type *self); 664 void CheckUnboxedTypeWidenable(TypeRelation *relation, Type *target, Type *self); 665 void CheckUnboxedTypesAssignable(TypeRelation *relation, Type *source, Type *target); 666 void CheckBoxedSourceTypeAssignable(TypeRelation *relation, Type *source, Type *target); 667 void CheckUnboxedSourceTypeWithWideningAssignable(TypeRelation *relation, Type *source, Type *target); 668 void CheckValidGenericTypeParameter(Type *argType, const lexer::SourcePosition &pos); 669 void ValidateNamespaceProperty(varbinder::Variable *property, const ETSObjectType *target, 670 const ir::Identifier *ident); 671 void ValidateResolvedProperty(varbinder::LocalVariable **property, const ETSObjectType *target, 672 const ir::Identifier *ident, PropertySearchFlags flags); 673 bool CheckNumberOfTypeArguments(ETSObjectType *type, ir::TSTypeParameterInstantiation *typeArgs, 674 const lexer::SourcePosition &pos); 675 ir::BlockStatement *FindFinalizerOfTryStatement(ir::AstNode *startFrom, const ir::AstNode *p); 676 void CheckExceptionClauseType(const std::vector<checker::ETSObjectType *> &exceptions, ir::CatchClause *catchClause, 677 checker::Type *clauseType); 678 ETSObjectType *GetRelevantArgumentedTypeFromChild(ETSObjectType *child, ETSObjectType *target); 679 util::StringView GetHashFromTypeArguments(const ArenaVector<Type *> &typeArgTypes); 680 util::StringView GetHashFromSubstitution(const Substitution *substitution, const bool isExtensionFuncFlag); 681 util::StringView GetHashFromFunctionType(ir::ETSFunctionType *type); 682 static ETSObjectType *GetOriginalBaseType(Type *object); 683 void SetArrayPreferredTypeForNestedMemberExpressions(ir::MemberExpression *expr, Type *annotationType); 684 bool IsExtensionETSFunctionType(const checker::Type *type); 685 bool IsExtensionAccessorFunctionType(const checker::Type *type); 686 bool IsArrayExprSizeValidForTuple(const ir::ArrayExpression *arrayExpr, const ETSTupleType *tuple); 687 void ModifyPreferredType(ir::ArrayExpression *arrayExpr, Type *newPreferredType); 688 Type *SelectGlobalIntegerTypeForNumeric(Type *type); 689 690 ir::ClassProperty *ClassPropToImplementationProp(ir::ClassProperty *classProp, varbinder::ClassScope *scope); 691 ir::Expression *GenerateImplicitInstantiateArg(const std::string &className); 692 void GenerateGetterSetterBody(ArenaVector<ir::Statement *> &stmts, ArenaVector<ir::Expression *> ¶ms, 693 ir::ClassProperty *field, varbinder::FunctionParamScope *paramScope, bool isSetter); 694 static ir::MethodDefinition *GenerateDefaultGetterSetter(ir::ClassProperty *property, ir::ClassProperty *field, 695 varbinder::ClassScope *scope, bool isSetter, 696 ETSChecker *checker); 697 void GenerateGetterSetterPropertyAndMethod(ir::ClassProperty *originalProp, ETSObjectType *classType); 698 void SetupGetterSetterFlags(ir::ClassProperty *originalProp, ETSObjectType *classType, ir::MethodDefinition *getter, 699 ir::MethodDefinition *setter, const bool inExternal); 700 Type *GetImportSpecifierObjectType(ir::ETSImportDeclaration *importDecl, ir::Identifier *ident); 701 void ImportNamespaceObjectTypeAddReExportType(ir::ETSImportDeclaration *importDecl, 702 checker::ETSObjectType *lastObjectType, ir::Identifier *ident); 703 bool CheckValidEqualReferenceType(checker::Type *const leftType, checker::Type *const rightType); 704 bool CheckVoidAnnotation(const ir::ETSPrimitiveType *typeAnnotation); 705 void ETSObjectTypeDeclNode(ETSChecker *checker, ETSObjectType *const objectType); 706 ir::CallExpression *CreateExtensionAccessorCall(ETSChecker *checker, ir::MemberExpression *expr, 707 ArenaVector<ir::Expression *> &&args); 708 static void SetPreferredTypeIfPossible(ir::Expression *expr, Type *targetType); 709 Signature *FindRelativeExtensionGetter(ir::MemberExpression *const expr, ETSFunctionType *funcType); 710 Signature *FindRelativeExtensionSetter(ir::MemberExpression *const expr, ETSFunctionType *funcType); 711 Type *GetExtensionAccessorReturnType(ir::MemberExpression *expr); 712 // Utility type handler functions 713 std::optional<ir::TypeNode *> GetUtilityTypeTypeParamNode(const ir::TSTypeParameterInstantiation *typeParams, 714 const std::string_view &utilityTypeName); 715 Type *HandleUtilityTypeParameterNode(const ir::TSTypeParameterInstantiation *typeParams, 716 const ir::Identifier *const ident); 717 // Partial 718 Type *CreatePartialType(Type *typeToBePartial); 719 Type *HandlePartialInterface(ir::TSInterfaceDeclaration *interfaceDecl, ETSObjectType *typeToBePartial); 720 721 ir::ClassProperty *CreateNullishProperty(ir::ClassProperty *prop, ir::ClassDefinition *newClassDefinition); 722 ir::ClassProperty *CreateNullishProperty(ir::ClassProperty *const prop, 723 ir::TSInterfaceDeclaration *const newTSInterfaceDefinition); 724 ir::MethodDefinition *CreateNullishAccessor(ir::MethodDefinition *const accessor, 725 ir::TSInterfaceDeclaration *interface); 726 ir::ClassProperty *CreateNullishPropertyFromAccessor(ir::MethodDefinition *const accessor, 727 ir::ClassDefinition *newClassDefinition); 728 void CreatePartialClassDeclaration(ir::ClassDefinition *newClassDefinition, ir::ClassDefinition *classDef); 729 ir::ETSTypeReference *BuildSuperPartialTypeReference(Type *superPartialType, 730 ir::TSTypeParameterInstantiation *superPartialRefTypeParams); 731 ir::TSInterfaceDeclaration *CreateInterfaceProto(util::StringView name, parser::Program *const interfaceDeclProgram, 732 const bool isStatic, const ir::ModifierFlags flags); 733 ir::TSTypeParameterInstantiation *CreateNewSuperPartialRefTypeParamsDecl( 734 ArenaMap<ir::TSTypeParameter *, ir::TSTypeParameter *> *likeSubstitution, const Type *const superPartialType, 735 ir::Expression *superRef); 736 ir::TSTypeParameterDeclaration *ProcessTypeParamAndGenSubstitution( 737 ir::TSTypeParameterDeclaration const *const thisTypeParams, 738 ArenaMap<ir::TSTypeParameter *, ir::TSTypeParameter *> *likeSubstitution, 739 ir::TSTypeParameterDeclaration *newTypeParams); 740 Type *CreatePartialTypeInterfaceDecl(ir::TSInterfaceDeclaration *const interfaceDecl, 741 ETSObjectType *const typeToBePartial, 742 ir::TSInterfaceDeclaration *partialInterface); 743 void CreatePartialTypeInterfaceMethods(ir::TSInterfaceDeclaration *const interfaceDecl, 744 ir::TSInterfaceDeclaration *partialInterface); 745 ir::ClassDefinition *CreateClassPrototype(util::StringView name, parser::Program *classDeclProgram); 746 varbinder::Variable *SearchNamesInMultiplePrograms(const std::set<const parser::Program *> &programs, 747 const std::set<util::StringView> &classNamesToFind); 748 std::pair<ir::ScriptFunction *, ir::Identifier *> CreateScriptFunctionForConstructor( 749 varbinder::FunctionScope *scope); 750 ir::MethodDefinition *CreateNonStaticClassInitializer(varbinder::ClassScope *classScope, 751 varbinder::RecordTable *recordTable); 752 // Readonly 753 Type *GetReadonlyType(Type *type); 754 void MakePropertiesReadonly(ETSObjectType *classType); 755 // Required 756 Type *HandleRequiredType(Type *typeToBeRequired); 757 void MakePropertiesNonNullish(ETSObjectType *classType); 758 template <PropertyType PROP_TYPE> 759 void MakePropertyNonNullish(ETSObjectType *classType, varbinder::LocalVariable *prop); 760 void ValidateObjectLiteralForRequiredType(const ETSObjectType *requiredType, 761 const ir::ObjectExpression *initObjExpr); 762 763 using NamedAccessMeta = std::tuple<ETSObjectType const *, checker::Type const *, const util::StringView>; 764 static NamedAccessMeta FormNamedAccessMetadata(varbinder::Variable const *prop); 765 766 // Smart cast support 767 [[nodiscard]] checker::Type *ResolveSmartType(checker::Type *sourceType, checker::Type *targetType); 768 [[nodiscard]] std::pair<Type *, Type *> CheckTestNullishCondition(Type *testedType, Type *actualType, bool strict); 769 [[nodiscard]] std::pair<Type *, Type *> CheckTestObjectCondition(ETSObjectType *testedType, Type *actualType, 770 bool strict); 771 [[nodiscard]] std::pair<Type *, Type *> CheckTestObjectCondition(ETSArrayType *testedType, Type *actualType); 772 773 void ApplySmartCast(varbinder::Variable const *variable, checker::Type *smartType) noexcept; 774 775 bool IsInLocalClass(const ir::AstNode *node) const; 776 // Exception 777 ETSObjectType *CheckExceptionOrErrorType(checker::Type *type, lexer::SourcePosition pos); 778 779 static Type *TryToInstantiate(Type *type, ArenaAllocator *allocator, TypeRelation *relation, 780 GlobalTypesHolder *globalTypes); 781 782 // Dynamic interop 783 template <typename T> 784 Signature *ResolveDynamicCallExpression(ir::Expression *callee, const ArenaVector<T *> &arguments, Language lang, 785 bool isConstruct); 786 ir::ClassProperty *CreateStaticReadonlyField(const char *name); 787 void BuildClassBodyFromDynamicImports(const ArenaVector<ir::ETSImportDeclaration *> &dynamicImports, 788 ArenaVector<ir::AstNode *> *classBody); 789 void BuildDynamicImportClass(); 790 void BuildLambdaObjectClass(ETSObjectType *functionalInterface, ir::TypeNode *retTypeAnnotation); 791 // Trailing lambda 792 void EnsureValidCurlyBrace(ir::CallExpression *callExpr); 793 794 // Extension function 795 void HandleUpdatedCallExpressionNode(ir::CallExpression *callExpr); 796 Signature *FindExtensionSetterInMap(util::StringView name, ETSObjectType *type); 797 Signature *FindExtensionGetterInMap(util::StringView name, ETSObjectType *type); 798 void InsertExtensionSetterToMap(util::StringView name, ETSObjectType *type, Signature *sig); 799 void InsertExtensionGetterToMap(util::StringView name, ETSObjectType *type, Signature *sig); 800 801 // Static invoke 802 void CheckInvokeMethodsLegitimacy(ETSObjectType *classType); 803 bool IsClassStaticMethod(checker::ETSObjectType *objType, checker::Signature *signature); 804 805 // Covariant and contravariant 806 void CheckTypeParameterVariance(ir::ClassDefinition *classDef); 807 808 checker::Type *CheckArrayElements(ir::ArrayExpression *init); 809 void ResolveReturnStatement(checker::Type *funcReturnType, checker::Type *argumentType, 810 ir::ScriptFunction *containingFunc, ir::ReturnStatement *st); 811 DynamicCallNames(bool isConstruct)812 auto *DynamicCallNames(bool isConstruct) 813 { 814 return &dynamicCallNames_[static_cast<uint32_t>(isConstruct)]; 815 } 816 DynamicCallNames(bool isConstruct)817 const auto *DynamicCallNames(bool isConstruct) const 818 { 819 return &dynamicCallNames_[static_cast<uint32_t>(isConstruct)]; 820 } 821 Mutex()822 std::recursive_mutex *Mutex() 823 { 824 return &mtx_; 825 } 826 827 template <typename T, typename... Args> AllocNode(Args &&...args)828 T *AllocNode(Args &&...args) 829 { 830 // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) 831 return util::NodeAllocator::ForceSetParent<T>(Allocator(), std::forward<Args>(args)...); 832 } 833 834 template <typename T, typename... Args> ProgramAllocNode(Args &&...args)835 T *ProgramAllocNode(Args &&...args) 836 { 837 // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) 838 return util::NodeAllocator::ForceSetParent<T>(ProgramAllocator(), std::forward<Args>(args)...); 839 } 840 841 ArenaVector<ConstraintCheckRecord> &PendingConstraintCheckRecords(); 842 size_t &ConstraintCheckScopesCount(); 843 844 ETSObjectType *GetCachedFunctionalInterface(ir::ETSFunctionType *type); 845 void CacheFunctionalInterface(ir::ETSFunctionType *type, ETSObjectType *ifaceType); 846 void CollectReturnStatements(ir::AstNode *parent); 847 ir::ETSParameterExpression *AddParam(util::StringView name, ir::TypeNode *type); 848 849 evaluate::ScopedDebugInfoPlugin *GetDebugInfoPlugin(); 850 const evaluate::ScopedDebugInfoPlugin *GetDebugInfoPlugin() const; 851 852 void SetDebugInfoPlugin(evaluate::ScopedDebugInfoPlugin *debugInfo); 853 854 using ClassBuilder = std::function<void(ArenaVector<ir::AstNode *> *)>; 855 using ClassInitializerBuilder = 856 std::function<void(ArenaVector<ir::Statement *> *, ArenaVector<ir::Expression *> *)>; 857 using MethodBuilder = std::function<void(ArenaVector<ir::Statement *> *, ArenaVector<ir::Expression *> *, Type **)>; 858 859 ir::ClassStaticBlock *CreateClassStaticInitializer(const ClassInitializerBuilder &builder, 860 ETSObjectType *type = nullptr); 861 ir::MethodDefinition *CreateClassInstanceInitializer(const ClassInitializerBuilder &builder, 862 ETSObjectType *type = nullptr); 863 ir::MethodDefinition *CreateClassMethod(std::string_view name, ir::ScriptFunctionFlags funcFlags, 864 ir::ModifierFlags modifierFlags, const MethodBuilder &builder); 865 ir::ClassDeclaration *BuildClass(util::StringView name, const ClassBuilder &builder); 866 const varbinder::Variable *GetTargetRef(const ir::MemberExpression *memberExpr); 867 868 void LogUnresolvedReferenceError(ir::Identifier *ident); 869 void WrongContextErrorClassifyByType(ir::Identifier *ident); 870 CreateOverloadSigContainer(Signature * overloadHelperSig)871 void CreateOverloadSigContainer(Signature *overloadHelperSig) 872 { 873 if (!overloadSigContainer_.empty()) { 874 overloadSigContainer_.pop_back(); 875 } 876 ES2PANDA_ASSERT(overloadSigContainer_.empty()); 877 overloadSigContainer_.insert(overloadSigContainer_.end(), overloadHelperSig); 878 } 879 GetOverloadSigContainer()880 ArenaVector<Signature *> &GetOverloadSigContainer() 881 { 882 ES2PANDA_ASSERT(overloadSigContainer_.size() == 1); 883 return overloadSigContainer_; 884 } 885 CleanUp()886 void CleanUp() override 887 { 888 Checker::CleanUp(); 889 arrayTypes_.clear(); 890 pendingConstraintCheckRecords_.clear(); 891 constraintCheckScopesCount_ = 0; 892 globalArraySignatures_.clear(); 893 GetCachedComputedAbstracts()->clear(); 894 for (auto &dynamicCallIntrinsicsMap : dynamicIntrinsics_) { 895 dynamicCallIntrinsicsMap.clear(); 896 } 897 898 for (auto &dynamicClassIntrinsicsMap : dynamicClasses_) { 899 dynamicClassIntrinsicsMap.clear(); 900 } 901 dynamicLambdaSignatureCache_.clear(); 902 functionalInterfaceCache_.clear(); 903 apparentTypes_.clear(); 904 for (auto &dynamicCallNamesMap : dynamicCallNames_) { 905 dynamicCallNamesMap.clear(); 906 } 907 elementStack_.clear(); 908 overloadSigContainer_.clear(); 909 } 910 911 // This helper finds the intersection of two callSignatures sets 912 // The result is stored in callSignatures of newly created ETSFunctionType 913 checker::ETSFunctionType *IntersectSignatureSets(const checker::ETSFunctionType *left, 914 const checker::ETSFunctionType *right); 915 GetCachedComputedAbstracts()916 ComputedAbstracts *GetCachedComputedAbstracts() 917 { 918 if (cachedComputedAbstracts_ == nullptr) { 919 InitCachedComputedAbstracts(); 920 } 921 return cachedComputedAbstracts_; 922 } 923 SetCachedComputedAbstracts(ComputedAbstracts * cachedComputedAbstracts)924 void SetCachedComputedAbstracts(ComputedAbstracts *cachedComputedAbstracts) 925 { 926 cachedComputedAbstracts_ = cachedComputedAbstracts; 927 } 928 InitCachedComputedAbstracts()929 void InitCachedComputedAbstracts() 930 { 931 // clang-format off 932 cachedComputedAbstracts_ = ProgramAllocator()->New<ArenaUnorderedMap<ETSObjectType *, 933 std::pair<ArenaVector<ETSFunctionType *>, 934 ArenaUnorderedSet<ETSObjectType *>>>>(ProgramAllocator()->Adapter()); 935 // clang-format on 936 } 937 938 private: 939 std::pair<const ir::Identifier *, ir::TypeNode *> GetTargetIdentifierAndType(ir::Identifier *ident); 940 void NotResolvedError(ir::Identifier *const ident, const varbinder::Variable *classVar, 941 const ETSObjectType *classType); 942 void ValidateCallExpressionIdentifier(ir::Identifier *const ident, Type *const type); 943 void ValidateNewClassInstanceIdentifier(ir::Identifier *const ident); 944 void ValidateMemberIdentifier(ir::Identifier *const ident); 945 void ValidateAssignmentIdentifier(ir::Identifier *const ident, Type *const type); 946 bool ValidateBinaryExpressionIdentifier(ir::Identifier *const ident, Type *const type); 947 ETSFunctionType *ResolveAccessorTypeByFlag(ir::MemberExpression *const memberExpr, ETSFunctionType *propType, 948 ETSFunctionType *funcType, PropertySearchFlags searchFlag); 949 std::vector<ResolveResult *> ValidateAccessor(ir::MemberExpression *const memberExpr, 950 varbinder::LocalVariable *const oAcc, varbinder::Variable *const eAcc, 951 PropertySearchFlags searchFlag); 952 ir::ClassProperty *FindClassProperty(const ETSObjectType *objectType, const ETSFunctionType *propType); 953 bool IsInitializedProperty(const ir::ClassDefinition *classDefinition, const ir::ClassProperty *prop); 954 bool FindPropertyInAssignment(const ir::AstNode *it, const std::string &targetName); 955 void ValidateReadonlyProperty(const ir::MemberExpression *memberExpr, const ETSFunctionType *propType, 956 lexer::SourcePosition sourcePos); 957 std::tuple<bool, bool> IsResolvedAndValue(const ir::Expression *expr, Type *type) const; 958 PropertySearchFlags GetSearchFlags(const ir::MemberExpression *memberExpr, const varbinder::Variable *targetRef); 959 PropertySearchFlags GetInitialSearchFlags(const ir::MemberExpression *memberExpr); 960 Type *GetTypeOfSetterGetter([[maybe_unused]] varbinder::Variable *var); 961 void IterateInVariableContext([[maybe_unused]] varbinder::Variable *const var); 962 bool CheckInit(ir::Identifier *ident, ir::TypeNode *typeAnnotation, ir::Expression *init, 963 checker::Type *annotationType); 964 void CheckItemCasesConstant(ArenaVector<ir::SwitchCaseStatement *> const &cases); 965 void CheckItemCasesDuplicate(ArenaVector<ir::SwitchCaseStatement *> const &cases); 966 967 template <typename EnumType> 968 EnumType *CreateEnumTypeFromEnumDeclaration(ir::TSEnumDeclaration const *const enumDecl); 969 970 std::pair<ir::ScriptFunction *, ir::Identifier *> CreateStaticScriptFunction( 971 ClassInitializerBuilder const &builder); 972 std::pair<ir::ScriptFunction *, ir::Identifier *> CreateScriptFunction(ClassInitializerBuilder const &builder); 973 974 template <typename T> 975 ir::MethodDefinition *CreateDynamicCallIntrinsic(ir::Expression *callee, const ArenaVector<T *> &arguments, 976 Language lang); 977 ir::ClassStaticBlock *CreateDynamicCallClassInitializer(Language lang, bool isConstruct); 978 ir::ClassStaticBlock *CreateDynamicModuleClassInitializer(const std::vector<ir::ETSImportDeclaration *> &imports); 979 ir::MethodDefinition *CreateDynamicModuleClassInitMethod(); 980 981 ir::MethodDefinition *CreateLambdaObjectClassInitializer(ETSObjectType *functionalInterface); 982 983 ir::MethodDefinition *CreateLambdaObjectClassInvokeMethod(Signature *invokeSignature, 984 ir::TypeNode *retTypeAnnotation); 985 986 void ClassInitializerFromImport(ir::ETSImportDeclaration *import, ArenaVector<ir::Statement *> *statements); 987 void EmitDynamicModuleClassInitCall(); DynamicCallIntrinsics(bool isConstruct)988 DynamicCallIntrinsicsMap *DynamicCallIntrinsics(bool isConstruct) 989 { 990 return &dynamicIntrinsics_[static_cast<size_t>(isConstruct)]; 991 } 992 993 ir::ClassDeclaration *GetDynamicClass(Language lang, bool isConstruct); 994 995 using Type2TypeMap = std::unordered_map<varbinder::Variable *, varbinder::Variable *>; 996 using TypeSet = std::unordered_set<varbinder::Variable *>; 997 bool CheckTypeParameterConstraint(ir::TSTypeParameter *param, Type2TypeMap &extends); 998 bool CheckDefaultTypeParameter(const ir::TSTypeParameter *param, TypeSet &typeParameterDecls); 999 1000 void SetUpTypeParameterConstraint(ir::TSTypeParameter *param); 1001 ETSObjectType *UpdateGlobalType(ETSObjectType *objType, util::StringView name); 1002 void CheckProgram(parser::Program *program, bool runAnalysis = false); 1003 void CheckWarnings(parser::Program *program, const util::Options &options); 1004 1005 Type *ResolveUnionUncheckedType(ArenaVector<checker::Type *> &&apparentTypes); 1006 1007 bool ComputeSuperType(ETSObjectType *type); 1008 1009 template <typename UType> 1010 UType HandleModulo(UType leftValue, UType rightValue); 1011 1012 template <typename FloatOrIntegerType, typename IntegerType = FloatOrIntegerType> 1013 Type *HandleBitWiseArithmetic(Type *leftValue, Type *rightValue, lexer::TokenType operationType); 1014 1015 template <typename TargetType> 1016 typename TargetType::UType GetOperand(Type *type); 1017 1018 template <typename... Args> 1019 ETSObjectType *AsETSObjectType(Type *(GlobalTypesHolder::*typeFunctor)(Args...), Args... args) const; 1020 Signature *GetMostSpecificSignature(ArenaVector<Signature *> &compatibleSignatures, 1021 const ArenaVector<ir::Expression *> &arguments, 1022 const lexer::SourcePosition &pos, TypeRelationFlag resolveFlags); 1023 ArenaVector<Signature *> CollectSignatures(ArenaVector<Signature *> &signatures, 1024 const ir::TSTypeParameterInstantiation *typeArguments, 1025 const ArenaVector<ir::Expression *> &arguments, 1026 const lexer::SourcePosition &pos, TypeRelationFlag resolveFlags); 1027 // Trailing lambda 1028 void MoveTrailingBlockToEnclosingBlockStatement(ir::CallExpression *callExpr); 1029 void TransformTraillingLambda(ir::CallExpression *callExpr, Signature *sig); 1030 ArenaVector<ir::Expression *> ExtendArgumentsWithFakeLamda(ir::CallExpression *callExpr); 1031 1032 // Static invoke 1033 bool SetStaticInvokeValues(ir::Identifier *const ident, ir::Identifier *classId, ir::Identifier *methodId, 1034 varbinder::LocalVariable *instantiateMethod); 1035 void CreateTransformedCallee(ir::Identifier *classId, ir::Identifier *methodId, ir::Identifier *const ident, 1036 varbinder::LocalVariable *instantiateMethod); 1037 bool TryTransformingToStaticInvoke(ir::Identifier *ident, const Type *resolvedType); 1038 1039 // Partial 1040 Type *HandleUnionForPartialType(ETSUnionType *typeToBePartial); 1041 Type *CreatePartialTypeParameter(ETSTypeParameter *typeToBePartial); 1042 Type *CreatePartialTypeClass(ETSObjectType *typeToBePartial, ir::AstNode *typeDeclNode); 1043 Type *CreatePartialTypeClassDef(ir::ClassDefinition *partialClassDef, ir::ClassDefinition *classDef, 1044 ETSObjectType *typeToBePartial, varbinder::RecordTable *recordTableToUse); 1045 void CreateConstructorForPartialType(ir::ClassDefinition *partialClassDef, checker::ETSObjectType *partialType, 1046 varbinder::RecordTable *recordTable); 1047 1048 // Check type alias for recursive cases 1049 bool IsAllowedTypeAliasRecursion(const ir::TSTypeAliasDeclaration *typeAliasNode, 1050 std::unordered_set<const ir::TSTypeAliasDeclaration *> &typeAliases); 1051 1052 ArrayMap arrayTypes_; 1053 ArenaVector<ConstraintCheckRecord> pendingConstraintCheckRecords_; 1054 size_t constraintCheckScopesCount_ {0}; 1055 GlobalArraySignatureMap globalArraySignatures_; 1056 ComputedAbstracts *cachedComputedAbstracts_ {nullptr}; 1057 // NOTE(aleksisch): Extract dynamic from checker to separate class 1058 std::array<DynamicCallIntrinsicsMap, 2U> dynamicIntrinsics_; 1059 std::array<DynamicClassIntrinsicsMap, 2U> dynamicClasses_; 1060 DynamicLambdaObjectSignatureMap dynamicLambdaSignatureCache_; 1061 FunctionalInterfaceMap functionalInterfaceCache_; 1062 TypeMapping apparentTypes_; 1063 std::array<DynamicCallNamesMap, 2U> dynamicCallNames_; 1064 std::recursive_mutex mtx_; 1065 evaluate::ScopedDebugInfoPlugin *debugInfoPlugin_ {nullptr}; 1066 std::unordered_set<ir::TSTypeAliasDeclaration *> elementStack_; 1067 ArenaVector<Signature *> overloadSigContainer_; 1068 }; 1069 1070 } // namespace ark::es2panda::checker 1071 1072 #endif /* CHECKER_H */ 1073