13af6ab5fSopenharmony_ci/** 23af6ab5fSopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 33af6ab5fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 43af6ab5fSopenharmony_ci * you may not use this file except in compliance with the License. 53af6ab5fSopenharmony_ci * You may obtain a copy of the License at 63af6ab5fSopenharmony_ci * 73af6ab5fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 83af6ab5fSopenharmony_ci * 93af6ab5fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 103af6ab5fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 113af6ab5fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 123af6ab5fSopenharmony_ci * See the License for the specific language governing permissions and 133af6ab5fSopenharmony_ci * limitations under the License. 143af6ab5fSopenharmony_ci */ 153af6ab5fSopenharmony_ci 163af6ab5fSopenharmony_ci#include "varbinder/variableFlags.h" 173af6ab5fSopenharmony_ci#include "checker/checker.h" 183af6ab5fSopenharmony_ci#include "checker/checkerContext.h" 193af6ab5fSopenharmony_ci#include "checker/types/ets/etsObjectType.h" 203af6ab5fSopenharmony_ci#include "checker/types/ets/etsTupleType.h" 213af6ab5fSopenharmony_ci#include "ir/astNode.h" 223af6ab5fSopenharmony_ci#include "lexer/token/tokenType.h" 233af6ab5fSopenharmony_ci#include "ir/base/catchClause.h" 243af6ab5fSopenharmony_ci#include "ir/expression.h" 253af6ab5fSopenharmony_ci#include "ir/typeNode.h" 263af6ab5fSopenharmony_ci#include "ir/base/scriptFunction.h" 273af6ab5fSopenharmony_ci#include "ir/base/classProperty.h" 283af6ab5fSopenharmony_ci#include "ir/base/methodDefinition.h" 293af6ab5fSopenharmony_ci#include "ir/statements/variableDeclarator.h" 303af6ab5fSopenharmony_ci#include "ir/statements/switchCaseStatement.h" 313af6ab5fSopenharmony_ci#include "ir/expressions/identifier.h" 323af6ab5fSopenharmony_ci#include "ir/expressions/arrayExpression.h" 333af6ab5fSopenharmony_ci#include "ir/expressions/callExpression.h" 343af6ab5fSopenharmony_ci#include "ir/expressions/memberExpression.h" 353af6ab5fSopenharmony_ci#include "ir/expressions/binaryExpression.h" 363af6ab5fSopenharmony_ci#include "ir/expressions/assignmentExpression.h" 373af6ab5fSopenharmony_ci#include "ir/statements/labelledStatement.h" 383af6ab5fSopenharmony_ci#include "ir/ets/etsFunctionType.h" 393af6ab5fSopenharmony_ci#include "ir/ets/etsNewClassInstanceExpression.h" 403af6ab5fSopenharmony_ci#include "ir/ts/tsTypeAliasDeclaration.h" 413af6ab5fSopenharmony_ci#include "ir/ts/tsEnumMember.h" 423af6ab5fSopenharmony_ci#include "ir/ts/tsTypeParameter.h" 433af6ab5fSopenharmony_ci#include "ir/ets/etsTypeReference.h" 443af6ab5fSopenharmony_ci#include "ir/ets/etsTypeReferencePart.h" 453af6ab5fSopenharmony_ci#include "varbinder/variable.h" 463af6ab5fSopenharmony_ci#include "varbinder/scope.h" 473af6ab5fSopenharmony_ci#include "varbinder/declaration.h" 483af6ab5fSopenharmony_ci#include "checker/ETSchecker.h" 493af6ab5fSopenharmony_ci#include "checker/ets/typeRelationContext.h" 503af6ab5fSopenharmony_ci#include "util/helpers.h" 513af6ab5fSopenharmony_ci 523af6ab5fSopenharmony_cinamespace ark::es2panda::checker { 533af6ab5fSopenharmony_civoid ETSChecker::ValidatePropertyAccess(varbinder::Variable *var, ETSObjectType *obj, const lexer::SourcePosition &pos) 543af6ab5fSopenharmony_ci{ 553af6ab5fSopenharmony_ci if ((Context().Status() & CheckerStatus::IGNORE_VISIBILITY) != 0U) { 563af6ab5fSopenharmony_ci return; 573af6ab5fSopenharmony_ci } 583af6ab5fSopenharmony_ci if (var->HasFlag(varbinder::VariableFlags::METHOD)) { 593af6ab5fSopenharmony_ci return; 603af6ab5fSopenharmony_ci } 613af6ab5fSopenharmony_ci 623af6ab5fSopenharmony_ci if (var->HasFlag(varbinder::VariableFlags::PRIVATE) || var->HasFlag(varbinder::VariableFlags::PROTECTED)) { 633af6ab5fSopenharmony_ci if ((Context().ContainingClass() == obj || 643af6ab5fSopenharmony_ci Context().ContainingClass()->GetOriginalBaseType() == obj->GetOriginalBaseType()) && 653af6ab5fSopenharmony_ci obj->IsPropertyInherited(var)) { 663af6ab5fSopenharmony_ci return; 673af6ab5fSopenharmony_ci } 683af6ab5fSopenharmony_ci 693af6ab5fSopenharmony_ci if (var->HasFlag(varbinder::VariableFlags::PROTECTED) && Context().ContainingClass()->IsDescendantOf(obj) && 703af6ab5fSopenharmony_ci obj->IsPropertyInherited(var)) { 713af6ab5fSopenharmony_ci return; 723af6ab5fSopenharmony_ci } 733af6ab5fSopenharmony_ci 743af6ab5fSopenharmony_ci auto *currentOutermost = Context().ContainingClass()->OutermostClass(); 753af6ab5fSopenharmony_ci auto *objOutermost = obj->OutermostClass(); 763af6ab5fSopenharmony_ci 773af6ab5fSopenharmony_ci if (currentOutermost != nullptr && objOutermost != nullptr && currentOutermost == objOutermost && 783af6ab5fSopenharmony_ci obj->IsPropertyInherited(var)) { 793af6ab5fSopenharmony_ci return; 803af6ab5fSopenharmony_ci } 813af6ab5fSopenharmony_ci 823af6ab5fSopenharmony_ci LogTypeError({"Property ", var->Name(), " is not visible here."}, pos); 833af6ab5fSopenharmony_ci var->SetTsType(GlobalTypeError()); 843af6ab5fSopenharmony_ci } 853af6ab5fSopenharmony_ci} 863af6ab5fSopenharmony_ci 873af6ab5fSopenharmony_civoid ETSChecker::ValidateCallExpressionIdentifier(ir::Identifier *const ident, varbinder::Variable *const resolved, 883af6ab5fSopenharmony_ci Type *const type) 893af6ab5fSopenharmony_ci{ 903af6ab5fSopenharmony_ci if (resolved->HasFlag(varbinder::VariableFlags::CLASS_OR_INTERFACE) && 913af6ab5fSopenharmony_ci ident->Parent()->AsCallExpression()->Callee() != ident) { 923af6ab5fSopenharmony_ci LogTypeError({"Class or interface '", ident->Name(), "' cannot be used as object"}, ident->Start()); 933af6ab5fSopenharmony_ci ident->Variable()->SetTsType(GlobalTypeError()); 943af6ab5fSopenharmony_ci } 953af6ab5fSopenharmony_ci 963af6ab5fSopenharmony_ci if (ident->Parent()->AsCallExpression()->Callee() != ident) { 973af6ab5fSopenharmony_ci return; 983af6ab5fSopenharmony_ci } 993af6ab5fSopenharmony_ci if (ident->Variable() != nullptr && // It should always be true! 1003af6ab5fSopenharmony_ci ident->Variable()->Declaration()->Node() != nullptr && 1013af6ab5fSopenharmony_ci ident->Variable()->Declaration()->Node()->IsImportNamespaceSpecifier()) { 1023af6ab5fSopenharmony_ci LogTypeError({"Namespace style identifier ", ident->Name(), " is not callable."}, ident->Start()); 1033af6ab5fSopenharmony_ci ident->Variable()->SetTsType(GlobalTypeError()); 1043af6ab5fSopenharmony_ci } 1053af6ab5fSopenharmony_ci if (type->IsETSFunctionType() || type->IsETSDynamicType() || 1063af6ab5fSopenharmony_ci (type->IsETSObjectType() && type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL))) { 1073af6ab5fSopenharmony_ci return; 1083af6ab5fSopenharmony_ci } 1093af6ab5fSopenharmony_ci // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) 1103af6ab5fSopenharmony_ci if (TryTransformingToStaticInvoke(ident, type)) { 1113af6ab5fSopenharmony_ci return; 1123af6ab5fSopenharmony_ci } 1133af6ab5fSopenharmony_ci 1143af6ab5fSopenharmony_ci if (type->IsETSUnionType()) { 1153af6ab5fSopenharmony_ci for (auto it : type->AsETSUnionType()->ConstituentTypes()) { 1163af6ab5fSopenharmony_ci if (it->IsETSFunctionType() || it->IsETSDynamicType() || 1173af6ab5fSopenharmony_ci (it->IsETSObjectType() && it->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL))) { 1183af6ab5fSopenharmony_ci return; 1193af6ab5fSopenharmony_ci } 1203af6ab5fSopenharmony_ci } 1213af6ab5fSopenharmony_ci } 1223af6ab5fSopenharmony_ci 1233af6ab5fSopenharmony_ci LogTypeError({"This expression is not callable."}, ident->Start()); 1243af6ab5fSopenharmony_ci ident->Variable()->SetTsType(GlobalTypeError()); 1253af6ab5fSopenharmony_ci} 1263af6ab5fSopenharmony_ci 1273af6ab5fSopenharmony_civoid ETSChecker::ValidateNewClassInstanceIdentifier(ir::Identifier *const ident, varbinder::Variable *const resolved) 1283af6ab5fSopenharmony_ci{ 1293af6ab5fSopenharmony_ci if (ident->Parent()->AsETSNewClassInstanceExpression()->GetTypeRef() == ident && (resolved != nullptr) && 1303af6ab5fSopenharmony_ci !resolved->HasFlag(varbinder::VariableFlags::CLASS_OR_INTERFACE)) { 1313af6ab5fSopenharmony_ci LogUnResolvedError(ident); 1323af6ab5fSopenharmony_ci return; 1333af6ab5fSopenharmony_ci } 1343af6ab5fSopenharmony_ci} 1353af6ab5fSopenharmony_ci 1363af6ab5fSopenharmony_civoid ETSChecker::ValidateMemberIdentifier(ir::Identifier *const ident, varbinder::Variable *const resolved, 1373af6ab5fSopenharmony_ci Type *const type) 1383af6ab5fSopenharmony_ci{ 1393af6ab5fSopenharmony_ci if (resolved->Declaration()->Node()->IsTSEnumDeclaration() && 1403af6ab5fSopenharmony_ci ident->Parent()->AsMemberExpression()->HasMemberKind(ir::MemberExpressionKind::ELEMENT_ACCESS)) { 1413af6ab5fSopenharmony_ci return; 1423af6ab5fSopenharmony_ci } 1433af6ab5fSopenharmony_ci if (ident->Parent()->AsMemberExpression()->IsComputed()) { 1443af6ab5fSopenharmony_ci if ((resolved != nullptr) && !resolved->Declaration()->PossibleTDZ()) { 1453af6ab5fSopenharmony_ci WrongContextErrorClassifyByType(ident, resolved); 1463af6ab5fSopenharmony_ci } 1473af6ab5fSopenharmony_ci 1483af6ab5fSopenharmony_ci return; 1493af6ab5fSopenharmony_ci } 1503af6ab5fSopenharmony_ci 1513af6ab5fSopenharmony_ci if (!IsReferenceType(type) && !type->IsETSEnumType() && !type->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)) { 1523af6ab5fSopenharmony_ci LogUnResolvedError(ident); 1533af6ab5fSopenharmony_ci return; 1543af6ab5fSopenharmony_ci } 1553af6ab5fSopenharmony_ci} 1563af6ab5fSopenharmony_ci 1573af6ab5fSopenharmony_civoid ETSChecker::ValidatePropertyOrDeclaratorIdentifier(ir::Identifier *const ident, 1583af6ab5fSopenharmony_ci varbinder::Variable *const resolved) 1593af6ab5fSopenharmony_ci{ 1603af6ab5fSopenharmony_ci const auto [target_ident, typeAnnotation] = GetTargetIdentifierAndType(ident); 1613af6ab5fSopenharmony_ci 1623af6ab5fSopenharmony_ci if ((resolved != nullptr) && resolved->TsType()->IsETSFunctionType()) { 1633af6ab5fSopenharmony_ci CheckEtsFunctionType(ident, target_ident); 1643af6ab5fSopenharmony_ci return; 1653af6ab5fSopenharmony_ci } 1663af6ab5fSopenharmony_ci 1673af6ab5fSopenharmony_ci if ((resolved != nullptr) && !resolved->Declaration()->PossibleTDZ()) { 1683af6ab5fSopenharmony_ci LogUnResolvedError(ident); 1693af6ab5fSopenharmony_ci return; 1703af6ab5fSopenharmony_ci } 1713af6ab5fSopenharmony_ci} 1723af6ab5fSopenharmony_ci 1733af6ab5fSopenharmony_civoid ETSChecker::ValidateAssignmentIdentifier(ir::Identifier *const ident, varbinder::Variable *const resolved, 1743af6ab5fSopenharmony_ci Type *const type) 1753af6ab5fSopenharmony_ci{ 1763af6ab5fSopenharmony_ci const auto *const assignmentExpr = ident->Parent()->AsAssignmentExpression(); 1773af6ab5fSopenharmony_ci if (assignmentExpr->Left() == ident && (resolved != nullptr) && !resolved->Declaration()->PossibleTDZ()) { 1783af6ab5fSopenharmony_ci WrongContextErrorClassifyByType(ident, resolved); 1793af6ab5fSopenharmony_ci return; 1803af6ab5fSopenharmony_ci } 1813af6ab5fSopenharmony_ci 1823af6ab5fSopenharmony_ci if (assignmentExpr->Right() == ident && (resolved != nullptr) && 1833af6ab5fSopenharmony_ci (!resolved->Declaration()->PossibleTDZ() && !type->IsETSFunctionType())) { 1843af6ab5fSopenharmony_ci WrongContextErrorClassifyByType(ident, resolved); 1853af6ab5fSopenharmony_ci return; 1863af6ab5fSopenharmony_ci } 1873af6ab5fSopenharmony_ci} 1883af6ab5fSopenharmony_ci 1893af6ab5fSopenharmony_cibool ETSChecker::ValidateBinaryExpressionIdentifier(ir::Identifier *const ident, Type *const type) 1903af6ab5fSopenharmony_ci{ 1913af6ab5fSopenharmony_ci const auto *const binaryExpr = ident->Parent()->AsBinaryExpression(); 1923af6ab5fSopenharmony_ci bool isFinished = false; 1933af6ab5fSopenharmony_ci if (binaryExpr->OperatorType() == lexer::TokenType::KEYW_INSTANCEOF && binaryExpr->Right() == ident) { 1943af6ab5fSopenharmony_ci if (!IsReferenceType(type)) { 1953af6ab5fSopenharmony_ci LogTypeError({R"(Using the "instance of" operator with non-object type ")", ident->Name(), "\""}, 1963af6ab5fSopenharmony_ci ident->Start()); 1973af6ab5fSopenharmony_ci ident->Variable()->SetTsType(GlobalTypeError()); 1983af6ab5fSopenharmony_ci } 1993af6ab5fSopenharmony_ci isFinished = true; 2003af6ab5fSopenharmony_ci } 2013af6ab5fSopenharmony_ci return isFinished; 2023af6ab5fSopenharmony_ci} 2033af6ab5fSopenharmony_ci 2043af6ab5fSopenharmony_civoid ETSChecker::ValidateResolvedIdentifier(ir::Identifier *const ident, varbinder::Variable *const resolved) 2053af6ab5fSopenharmony_ci{ 2063af6ab5fSopenharmony_ci auto *smartType = Context().GetSmartCast(resolved); 2073af6ab5fSopenharmony_ci auto *const resolvedType = GetApparentType(smartType != nullptr ? smartType : GetTypeOfVariable(resolved)); 2083af6ab5fSopenharmony_ci 2093af6ab5fSopenharmony_ci switch (ident->Parent()->Type()) { 2103af6ab5fSopenharmony_ci case ir::AstNodeType::CALL_EXPRESSION: { 2113af6ab5fSopenharmony_ci // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) 2123af6ab5fSopenharmony_ci ValidateCallExpressionIdentifier(ident, resolved, resolvedType); 2133af6ab5fSopenharmony_ci break; 2143af6ab5fSopenharmony_ci } 2153af6ab5fSopenharmony_ci case ir::AstNodeType::ETS_NEW_CLASS_INSTANCE_EXPRESSION: { 2163af6ab5fSopenharmony_ci ValidateNewClassInstanceIdentifier(ident, resolved); 2173af6ab5fSopenharmony_ci break; 2183af6ab5fSopenharmony_ci } 2193af6ab5fSopenharmony_ci case ir::AstNodeType::MEMBER_EXPRESSION: { 2203af6ab5fSopenharmony_ci ValidateMemberIdentifier(ident, resolved, resolvedType); 2213af6ab5fSopenharmony_ci break; 2223af6ab5fSopenharmony_ci } 2233af6ab5fSopenharmony_ci case ir::AstNodeType::BINARY_EXPRESSION: { 2243af6ab5fSopenharmony_ci if (ValidateBinaryExpressionIdentifier(ident, resolvedType)) { 2253af6ab5fSopenharmony_ci return; 2263af6ab5fSopenharmony_ci } 2273af6ab5fSopenharmony_ci 2283af6ab5fSopenharmony_ci [[fallthrough]]; 2293af6ab5fSopenharmony_ci } 2303af6ab5fSopenharmony_ci case ir::AstNodeType::UPDATE_EXPRESSION: 2313af6ab5fSopenharmony_ci case ir::AstNodeType::UNARY_EXPRESSION: { 2323af6ab5fSopenharmony_ci if (resolved != nullptr && !resolved->Declaration()->PossibleTDZ()) { 2333af6ab5fSopenharmony_ci WrongContextErrorClassifyByType(ident, resolved); 2343af6ab5fSopenharmony_ci } 2353af6ab5fSopenharmony_ci break; 2363af6ab5fSopenharmony_ci } 2373af6ab5fSopenharmony_ci case ir::AstNodeType::CLASS_PROPERTY: 2383af6ab5fSopenharmony_ci case ir::AstNodeType::VARIABLE_DECLARATOR: { 2393af6ab5fSopenharmony_ci ValidatePropertyOrDeclaratorIdentifier(ident, resolved); 2403af6ab5fSopenharmony_ci break; 2413af6ab5fSopenharmony_ci } 2423af6ab5fSopenharmony_ci case ir::AstNodeType::ASSIGNMENT_EXPRESSION: { 2433af6ab5fSopenharmony_ci ValidateAssignmentIdentifier(ident, resolved, resolvedType); 2443af6ab5fSopenharmony_ci break; 2453af6ab5fSopenharmony_ci } 2463af6ab5fSopenharmony_ci default: { 2473af6ab5fSopenharmony_ci if (resolved != nullptr && !resolved->Declaration()->PossibleTDZ() && !resolvedType->IsETSFunctionType()) { 2483af6ab5fSopenharmony_ci WrongContextErrorClassifyByType(ident, resolved); 2493af6ab5fSopenharmony_ci } 2503af6ab5fSopenharmony_ci break; 2513af6ab5fSopenharmony_ci } 2523af6ab5fSopenharmony_ci } 2533af6ab5fSopenharmony_ci} 2543af6ab5fSopenharmony_ci 2553af6ab5fSopenharmony_civoid ETSChecker::ValidateUnaryOperatorOperand(varbinder::Variable *variable) 2563af6ab5fSopenharmony_ci{ 2573af6ab5fSopenharmony_ci if (variable == nullptr || IsVariableGetterSetter(variable) || variable->Declaration() == nullptr) { 2583af6ab5fSopenharmony_ci return; 2593af6ab5fSopenharmony_ci } 2603af6ab5fSopenharmony_ci 2613af6ab5fSopenharmony_ci if (variable->Declaration()->IsConstDecl() || variable->Declaration()->IsReadonlyDecl()) { 2623af6ab5fSopenharmony_ci std::string_view fieldType = variable->Declaration()->IsConstDecl() ? "constant" : "readonly"; 2633af6ab5fSopenharmony_ci if (HasStatus(CheckerStatus::IN_CONSTRUCTOR | CheckerStatus::IN_STATIC_BLOCK) && 2643af6ab5fSopenharmony_ci !variable->HasFlag(varbinder::VariableFlags::EXPLICIT_INIT_REQUIRED)) { 2653af6ab5fSopenharmony_ci LogTypeError({"Cannot reassign ", fieldType, " ", variable->Name()}, 2663af6ab5fSopenharmony_ci variable->Declaration()->Node()->Start()); 2673af6ab5fSopenharmony_ci variable->SetTsType(GlobalTypeError()); 2683af6ab5fSopenharmony_ci return; 2693af6ab5fSopenharmony_ci } 2703af6ab5fSopenharmony_ci if (!HasStatus(CheckerStatus::IN_CONSTRUCTOR | CheckerStatus::IN_STATIC_BLOCK)) { 2713af6ab5fSopenharmony_ci LogTypeError({"Cannot assign to a ", fieldType, " variable ", variable->Name()}, 2723af6ab5fSopenharmony_ci variable->Declaration()->Node()->Start()); 2733af6ab5fSopenharmony_ci variable->SetTsType(GlobalTypeError()); 2743af6ab5fSopenharmony_ci } 2753af6ab5fSopenharmony_ci } 2763af6ab5fSopenharmony_ci} 2773af6ab5fSopenharmony_ci 2783af6ab5fSopenharmony_civoid ETSChecker::ValidateGenericTypeAliasForClonedNode(ir::TSTypeAliasDeclaration *const typeAliasNode, 2793af6ab5fSopenharmony_ci const ir::TSTypeParameterInstantiation *const exactTypeParams) 2803af6ab5fSopenharmony_ci{ 2813af6ab5fSopenharmony_ci static std::string_view const TRANSFORMATION_NAME = __func__; 2823af6ab5fSopenharmony_ci 2833af6ab5fSopenharmony_ci // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) 2843af6ab5fSopenharmony_ci auto *const clonedNode = typeAliasNode->TypeAnnotation()->Clone(Allocator(), typeAliasNode); 2853af6ab5fSopenharmony_ci 2863af6ab5fSopenharmony_ci // Basic check, we really don't want to change the original type nodes, more precise checking should be made 2873af6ab5fSopenharmony_ci ASSERT(clonedNode != typeAliasNode->TypeAnnotation()); 2883af6ab5fSopenharmony_ci 2893af6ab5fSopenharmony_ci // Currently only reference types are checked. This should be extended for other types in a follow up patch, but for 2903af6ab5fSopenharmony_ci // complete usability, if the type isn't a simple reference type, then doN't check type alias declaration at all. 2913af6ab5fSopenharmony_ci bool checkTypealias = true; 2923af6ab5fSopenharmony_ci 2933af6ab5fSopenharmony_ci // Only transforming a temporary cloned node, so no modification is made in the AST 2943af6ab5fSopenharmony_ci clonedNode->TransformChildrenRecursively( 2953af6ab5fSopenharmony_ci [this, &checkTypealias, &exactTypeParams, typeAliasNode](ir::AstNode *const node) -> ir::AstNode * { 2963af6ab5fSopenharmony_ci if (!node->IsETSTypeReference()) { 2973af6ab5fSopenharmony_ci return node; 2983af6ab5fSopenharmony_ci } 2993af6ab5fSopenharmony_ci 3003af6ab5fSopenharmony_ci const auto *const nodeIdent = node->AsETSTypeReference()->Part()->Name()->AsIdentifier(); 3013af6ab5fSopenharmony_ci 3023af6ab5fSopenharmony_ci size_t typeParamIdx = 0; 3033af6ab5fSopenharmony_ci for (const auto *const typeParam : typeAliasNode->TypeParams()->Params()) { 3043af6ab5fSopenharmony_ci if (typeParam->Name()->AsIdentifier()->Variable() == nodeIdent->Variable()) { 3053af6ab5fSopenharmony_ci break; 3063af6ab5fSopenharmony_ci } 3073af6ab5fSopenharmony_ci typeParamIdx++; 3083af6ab5fSopenharmony_ci } 3093af6ab5fSopenharmony_ci 3103af6ab5fSopenharmony_ci if (typeParamIdx == typeAliasNode->TypeParams()->Params().size()) { 3113af6ab5fSopenharmony_ci return node; 3123af6ab5fSopenharmony_ci } 3133af6ab5fSopenharmony_ci 3143af6ab5fSopenharmony_ci auto *const typeParamType = exactTypeParams->Params().at(typeParamIdx); 3153af6ab5fSopenharmony_ci 3163af6ab5fSopenharmony_ci if (!typeParamType->IsETSTypeReference()) { 3173af6ab5fSopenharmony_ci checkTypealias = false; 3183af6ab5fSopenharmony_ci return node; 3193af6ab5fSopenharmony_ci } 3203af6ab5fSopenharmony_ci 3213af6ab5fSopenharmony_ci return typeParamType->Clone(Allocator(), nullptr); 3223af6ab5fSopenharmony_ci }, 3233af6ab5fSopenharmony_ci TRANSFORMATION_NAME); 3243af6ab5fSopenharmony_ci 3253af6ab5fSopenharmony_ci if (checkTypealias) { 3263af6ab5fSopenharmony_ci clonedNode->Check(this); 3273af6ab5fSopenharmony_ci } 3283af6ab5fSopenharmony_ci} 3293af6ab5fSopenharmony_ci 3303af6ab5fSopenharmony_cibool ETSChecker::ValidateTupleMinElementSize(ir::ArrayExpression *const arrayExpr, ETSTupleType *tuple) 3313af6ab5fSopenharmony_ci{ 3323af6ab5fSopenharmony_ci if (arrayExpr->Elements().size() < static_cast<size_t>(tuple->GetMinTupleSize())) { 3333af6ab5fSopenharmony_ci LogTypeError({"Few elements in array initializer for tuple with size of ", 3343af6ab5fSopenharmony_ci static_cast<size_t>(tuple->GetMinTupleSize())}, 3353af6ab5fSopenharmony_ci arrayExpr->Start()); 3363af6ab5fSopenharmony_ci return false; 3373af6ab5fSopenharmony_ci } 3383af6ab5fSopenharmony_ci return true; 3393af6ab5fSopenharmony_ci} 3403af6ab5fSopenharmony_ci} // namespace ark::es2panda::checker 341