From 0985a6e7423afcc8ec187967fad805d5052e2fce Mon Sep 17 00:00:00 2001 From: Klimentieva Date: Tue, 15 Jul 2025 17:38:04 +0300 Subject: [PATCH] codecheck fix Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICMKCB Change-Id: I501223b13011aa3849bd94637e5e1a470dce51ba Signed-off-by: Klimentieva --- .../ets/constantExpressionLowering.cpp | 1 + .../lowering/ets/declareOverloadLowering.cpp | 6 +- ...defaultParametersInConstructorLowering.cpp | 17 ++-- .../lowering/ets/genericBridgesLowering.cpp | 7 +- .../compiler/lowering/ets/lambdaLowering.cpp | 93 ++++++++++++------- ets2panda/declgen_ets2ts/declgenEts2Ts.cpp | 2 + ets2panda/ir/ets/etsNeverType.cpp | 6 +- ets2panda/ir/ets/etsParameterExpression.cpp | 18 +++- ets2panda/ir/ets/etsPrimitiveType.cpp | 6 +- ets2panda/ir/ets/etsTuple.cpp | 6 +- ets2panda/ir/ets/etsTypeReference.cpp | 12 ++- 11 files changed, 117 insertions(+), 57 deletions(-) diff --git a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp index 96da74bb4b..df42a65ed4 100644 --- a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp +++ b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp @@ -660,6 +660,7 @@ ir::AstNode *ConstantExpressionLowering::FoldUnaryBooleanConstant(ir::UnaryExpre } auto resNode = util::NodeAllocator::Alloc(context_->allocator, result); + ES2PANDA_ASSERT(resNode != nullptr); resNode->SetParent(unary->Parent()); resNode->SetRange(unary->Range()); return resNode; diff --git a/ets2panda/compiler/lowering/ets/declareOverloadLowering.cpp b/ets2panda/compiler/lowering/ets/declareOverloadLowering.cpp index 1d8d05f946..595c2736fe 100644 --- a/ets2panda/compiler/lowering/ets/declareOverloadLowering.cpp +++ b/ets2panda/compiler/lowering/ets/declareOverloadLowering.cpp @@ -64,7 +64,7 @@ void BuildOverloadHelperFunction(public_lib::Context *ctx, ir::MethodDefinition auto *varBinder = ctx->checker->VarBinder()->AsETSBinder(); auto const &[minArg, maxArg, needHelperOverload, isDeclare, hasRestVar, returnVoid] = method->GetOverloadInfo(); - ES2PANDA_ASSERT(needHelperOverload); + ES2PANDA_ASSERT(needHelperOverload && method->Function() != nullptr); auto params = ArenaVector(allocator->Adapter()); GenerateOverloadHelperParams(ctx, minArg, maxArg, hasRestVar, params); @@ -77,6 +77,7 @@ void BuildOverloadHelperFunction(public_lib::Context *ctx, ir::MethodDefinition allocator, ir::ScriptFunction::ScriptFunctionData {nullptr, ir::FunctionSignature(nullptr, std::move(params), returnAnno), functionFlag, method->Function()->Modifiers()}); + ES2PANDA_ASSERT(func != nullptr && method->Id() != nullptr); auto *methodId = ctx->AllocNode(method->Id()->Name(), allocator); func->SetIdent(methodId); auto *funcExpr = ctx->AllocNode(func); @@ -85,7 +86,8 @@ void BuildOverloadHelperFunction(public_lib::Context *ctx, ir::MethodDefinition method->Modifiers(), allocator, false); method->AddOverload(helperOverload); - ES2PANDA_ASSERT(helperOverload->Function()); + ES2PANDA_ASSERT(helperOverload->Function() != nullptr); + ES2PANDA_ASSERT(helperOverload->Id() != nullptr); helperOverload->Function()->ClearFlag((ir::ScriptFunctionFlags::OVERLOAD)); helperOverload->SetParent(method); diff --git a/ets2panda/compiler/lowering/ets/defaultParametersInConstructorLowering.cpp b/ets2panda/compiler/lowering/ets/defaultParametersInConstructorLowering.cpp index ed4192d4e8..aa27b63966 100644 --- a/ets2panda/compiler/lowering/ets/defaultParametersInConstructorLowering.cpp +++ b/ets2panda/compiler/lowering/ets/defaultParametersInConstructorLowering.cpp @@ -134,7 +134,7 @@ static ir::BlockStatement *CreateFunctionBody(ir::MethodDefinition *method, publ auto const allocator = ctx->allocator; ArenaVector funcStatements(allocator->Adapter()); - ES2PANDA_ASSERT(method->Id()); + ES2PANDA_ASSERT(method->Id() != nullptr); auto *const callee = util::NodeAllocator::ForceSetParent(allocator, method->Id()->Name(), allocator); @@ -142,6 +142,7 @@ static ir::BlockStatement *CreateFunctionBody(ir::MethodDefinition *method, publ auto *paramInst = CreateTypeParameterInstantiation(method, ctx); auto *callExpression = util::NodeAllocator::ForceSetParent( allocator, accessor != nullptr ? accessor : callee, std::move(funcCallArgs), paramInst, false, false); + ES2PANDA_ASSERT(callExpression != nullptr); callExpression->SetRange(method->Range()); // NOTE: Used to locate the original node when an error occurs funcStatements.push_back(util::NodeAllocator::ForceSetParent(allocator, callExpression)); @@ -182,14 +183,15 @@ static void CreateFunctionOverload(ir::MethodDefinition *method, ArenaVectorallocator; auto *funcExpression = CreateFunctionExpression(method, ctx, std::move(funcDefinitionArgs), std::move(funcCallArgs)); + ES2PANDA_ASSERT(funcExpression != nullptr); auto *ident = funcExpression->Function()->Id()->Clone(allocator, nullptr); auto *const overloadMethod = util::NodeAllocator::ForceSetParent( allocator, method->Kind(), ident, funcExpression, method->Modifiers(), allocator, false); + ES2PANDA_ASSERT(overloadMethod != nullptr && overloadMethod->Function() != nullptr); overloadMethod->Function()->AddFlag(ir::ScriptFunctionFlags::OVERLOAD); overloadMethod->SetRange(funcExpression->Range()); - ES2PANDA_ASSERT(overloadMethod->Function()); if (!method->IsDeclare() && method->Parent()->IsTSInterfaceBody()) { overloadMethod->Function()->Body()->AsBlockStatement()->Statements().clear(); } @@ -235,6 +237,7 @@ static void ClearOptionalParameters(public_lib::Context *ctx, ir::ScriptFunction static void ProcessGlobalFunctionDefinition(ir::MethodDefinition *method, public_lib::Context *ctx) { + ES2PANDA_ASSERT(method->Function() != nullptr); auto allocator = ctx->allocator; ExpandOptionalParameterAnnotationsToUnions(ctx, method->Function()); auto const ¶ms = method->Function()->Params(); @@ -252,10 +255,12 @@ static void ProcessGlobalFunctionDefinition(ir::MethodDefinition *method, public for (size_t i = 0; i < params.size() - paramsToCut; ++i) { auto param = params[i]->AsETSParameterExpression(); - callArgs.push_back(param->Ident()->CloneReference(allocator, nullptr)->AsIdentifier()); - ES2PANDA_ASSERT(param->Ident()->Clone(allocator, nullptr)); - functionParams.push_back(allocator->New( - param->Ident()->Clone(allocator, nullptr)->AsIdentifier(), false, allocator)); + auto cloneRef = param->Ident()->CloneReference(allocator, nullptr); + auto clone = param->Ident()->Clone(allocator, nullptr); + ES2PANDA_ASSERT(cloneRef != nullptr && clone != nullptr); + callArgs.push_back(cloneRef->AsIdentifier()); + functionParams.push_back( + allocator->New(clone->AsIdentifier(), false, allocator)); } for (size_t i = params.size() - paramsToCut; i < params.size(); ++i) { diff --git a/ets2panda/compiler/lowering/ets/genericBridgesLowering.cpp b/ets2panda/compiler/lowering/ets/genericBridgesLowering.cpp index 0805641419..0ab8c21d35 100644 --- a/ets2panda/compiler/lowering/ets/genericBridgesLowering.cpp +++ b/ets2panda/compiler/lowering/ets/genericBridgesLowering.cpp @@ -83,10 +83,9 @@ void GenericBridgesPhase::AddGenericBridge(ir::ClassDefinition const *const clas typeNodes.reserve(2U * baseSignature->Params().size() + 2U); auto const sourceCode = CreateMethodDefinitionString(classDefinition, baseSignature, derivedFunction, typeNodes); - - auto *const bridgeMethod = - parser->CreateFormattedClassMethodDefinition(sourceCode, typeNodes)->AsMethodDefinition(); - ES2PANDA_ASSERT(bridgeMethod); + auto *const bridgeMethodDefinition = parser->CreateFormattedClassMethodDefinition(sourceCode, typeNodes); + auto *const bridgeMethod = bridgeMethodDefinition->AsMethodDefinition(); + ES2PANDA_ASSERT(bridgeMethodDefinition != nullptr && bridgeMethod != nullptr && methodDefinition->Id() != nullptr); bridgeMethod->AddModifier(methodDefinition->Modifiers()); bridgeMethod->ClearModifier(ir::ModifierFlags::NATIVE | ir::ModifierFlags::ABSTRACT); bridgeMethod->AddAstNodeFlags(methodDefinition->GetAstNodeFlags()); diff --git a/ets2panda/compiler/lowering/ets/lambdaLowering.cpp b/ets2panda/compiler/lowering/ets/lambdaLowering.cpp index ef4a95baf7..7258b63b24 100644 --- a/ets2panda/compiler/lowering/ets/lambdaLowering.cpp +++ b/ets2panda/compiler/lowering/ets/lambdaLowering.cpp @@ -91,6 +91,31 @@ static util::StringView CreateCalleeName(ArenaAllocator *allocator) return name.View(); } +static void ProcessTypeParameterProperties(checker::ETSTypeParameter *oldTypeParam, + checker::ETSTypeParameter *newTypeParam, + ir::TSTypeParameter *newTypeParamNode, checker::Substitution *substitution, + public_lib::Context *ctx) +{ + auto *allocator = ctx->allocator; + auto *checker = ctx->checker->AsETSChecker(); + + if (auto *oldConstraint = oldTypeParam->GetConstraintType(); oldConstraint != nullptr) { + auto *newConstraint = oldConstraint->Substitute(checker->Relation(), substitution); + newTypeParam->SetConstraintType(newConstraint); + auto *newConstraintNode = allocator->New(newConstraint, allocator); + newTypeParamNode->SetConstraint(newConstraintNode); + newConstraintNode->SetParent(newTypeParamNode); + } + + if (auto *oldDefault = oldTypeParam->GetDefaultType(); oldDefault != nullptr) { + auto *newDefault = oldDefault->Substitute(checker->Relation(), substitution); + newTypeParam->SetDefaultType(newDefault); + auto *newDefaultNode = allocator->New(newDefault, allocator); + newTypeParamNode->SetDefaultType(newDefaultNode); + newDefaultNode->SetParent(newTypeParamNode); + } +} + static std::pair CloneTypeParams( public_lib::Context *ctx, ir::TSTypeParameterDeclaration *oldIrTypeParams, ir::ScriptFunction *enclosingFunction, varbinder::Scope *enclosingScope) @@ -106,6 +131,7 @@ static std::pair Clon auto newTypeParams = ArenaVector(allocator->Adapter()); auto newTypeParamNodes = ArenaVector(allocator->Adapter()); auto *substitution = checker->NewSubstitution(); + ES2PANDA_ASSERT(substitution != nullptr && newScope != nullptr); for (size_t ix = 0; ix < oldIrTypeParams->Params().size(); ix++) { auto *oldTypeParamNode = oldIrTypeParams->Params()[ix]; @@ -114,14 +140,13 @@ static std::pair Clon auto *newTypeParamNode = util::NodeAllocator::ForceSetParent(allocator, newTypeParamId, nullptr, nullptr, allocator); auto *newTypeParam = allocator->New(); - ES2PANDA_ASSERT(newTypeParam); - newTypeParam->SetDeclNode(newTypeParamNode); - auto *newTypeParamDecl = allocator->New(newTypeParamId->Name()); - newTypeParamDecl->BindNode(newTypeParamNode); auto *newTypeParamVar = allocator->New(newTypeParamDecl, varbinder::VariableFlags::TYPE_PARAMETER); + ES2PANDA_ASSERT(newTypeParam != nullptr && newTypeParamDecl != nullptr && newTypeParamVar != nullptr); + newTypeParam->SetDeclNode(newTypeParamNode); + newTypeParamDecl->BindNode(newTypeParamNode); newTypeParamVar->SetTsType(newTypeParam); newScope->InsertBinding(newTypeParamId->Name(), newTypeParamVar); newTypeParamId->SetVariable(newTypeParamVar); @@ -133,23 +158,12 @@ static std::pair Clon for (size_t ix = 0; ix < oldIrTypeParams->Params().size(); ix++) { auto *oldTypeParam = enclosingFunction->Signature()->TypeParams()[ix]->AsETSTypeParameter(); - - if (auto *oldConstraint = oldTypeParam->GetConstraintType(); oldConstraint != nullptr) { - auto *newConstraint = oldConstraint->Substitute(checker->Relation(), substitution); - newTypeParams[ix]->SetConstraintType(newConstraint); - newTypeParamNodes[ix]->SetConstraint(allocator->New(newConstraint, allocator)); - newTypeParamNodes[ix]->Constraint()->SetParent(newTypeParamNodes[ix]); - } - if (auto *oldDefault = oldTypeParam->GetDefaultType(); oldDefault != nullptr) { - auto *newDefault = oldDefault->Substitute(checker->Relation(), substitution); - newTypeParams[ix]->SetDefaultType(newDefault); - newTypeParamNodes[ix]->SetDefaultType(allocator->New(newDefault, allocator)); - newTypeParamNodes[ix]->DefaultType()->SetParent(newTypeParamNodes[ix]); - } + ProcessTypeParameterProperties(oldTypeParam, newTypeParams[ix], newTypeParamNodes[ix], substitution, ctx); } auto *newIrTypeParams = util::NodeAllocator::ForceSetParent( allocator, std::move(newTypeParamNodes), oldIrTypeParams->RequiredParams()); + ES2PANDA_ASSERT(newIrTypeParams != nullptr); newIrTypeParams->SetScope(newScope); return {newIrTypeParams, substitution}; @@ -158,6 +172,20 @@ static std::pair Clon using ParamsAndVarMap = std::pair, ArenaMap>; +inline static varbinder::Variable *InitNewParameterVariable(varbinder::VarBinder *varBinder, + ir::ETSParameterExpression *param, + checker::Type *newParamType, + varbinder::ParamScope *paramScope) +{ + ES2PANDA_ASSERT(param != nullptr); + auto *var = varBinder->AddParamDecl(param); + var->SetTsType(newParamType); + var->SetScope(paramScope); + param->SetVariable(var); + param->SetTsType(newParamType); + return var; +} + ParamsAndVarMap CreateLambdaCalleeParameters(public_lib::Context *ctx, ir::ArrowFunctionExpression *lambda, ArenaSet const &captured, varbinder::ParamScope *paramScope, checker::Substitution *substitution) @@ -176,11 +204,8 @@ ParamsAndVarMap CreateLambdaCalleeParameters(public_lib::Context *ctx, ir::Arrow allocator, capturedVar->Name(), allocator->New(newType, allocator), allocator); auto param = util::NodeAllocator::ForceSetParent(allocator, newId, false, allocator); - auto *var = varBinder->AddParamDecl(param); - var->SetTsType(newType); - var->SetScope(paramScope); - param->SetVariable(var); - param->SetTsType(newType); + ES2PANDA_ASSERT(param != nullptr); + auto *var = InitNewParameterVariable(varBinder, param, newType, paramScope); resParams.push_back(param); varMap[capturedVar] = var; } @@ -189,17 +214,14 @@ ParamsAndVarMap CreateLambdaCalleeParameters(public_lib::Context *ctx, ir::Arrow auto *oldParamType = oldParam->AsETSParameterExpression()->Ident()->TsType(); auto *newParamType = oldParamType->Substitute(checker->Relation(), substitution); auto *newParam = oldParam->AsETSParameterExpression()->Clone(allocator, nullptr); - ES2PANDA_ASSERT(newParam); + ES2PANDA_ASSERT(newParam != nullptr); if (newParam->IsOptional()) { newParam->SetOptional(false); newParamType = checker->CreateETSUnionType({newParamType, checker->GlobalETSUndefinedType()}); } + newParam->SetTypeAnnotation(allocator->New(newParamType, allocator)); - auto *var = varBinder->AddParamDecl(newParam); - var->SetTsType(newParamType); - var->SetScope(paramScope); - newParam->SetVariable(var); - newParam->SetTsType(newParamType); + auto *var = InitNewParameterVariable(varBinder, newParam, newParamType, paramScope); newParam->Ident()->SetTsType(newParamType); if (newParam->IsRestParameter()) { newParam->TypeAnnotation()->SetParent(newParam->RestParameter()); @@ -576,7 +598,7 @@ static ArenaVector CreateRestArgumentsArrayReall lciInfo->restParameterIdentifier, lciInfo->restArgumentIdentifier, restParameterIndex, spreadArrIterator, checker->MaybeBoxType(elementType), restParameterIndex, restParameterIndex); } - ES2PANDA_ASSERT(args); + ES2PANDA_ASSERT(args != nullptr); return ArenaVector(std::move(args->AsBlockStatement()->Statements())); } @@ -587,10 +609,11 @@ static void CreateInvokeMethodRestParameter(public_lib::Context *ctx, LambdaClas auto *checker = ctx->checker->AsETSChecker(); auto *restIdent = Gensym(allocator); - ES2PANDA_ASSERT(restIdent); + ES2PANDA_ASSERT(restIdent != nullptr); lciInfo->restParameterIdentifier = restIdent->Name(); lciInfo->restArgumentIdentifier = GenName(allocator).View(); auto *spread = allocator->New(ir::AstNodeType::REST_ELEMENT, allocator, restIdent); + ES2PANDA_ASSERT(spread != nullptr); auto *arr = lciInfo->lambdaSignature->RestVar()->TsType()->IsETSTupleType() ? lciInfo->lambdaSignature->RestVar()->TsType() : checker->CreateETSArrayType(checker->GlobalETSAnyType()); @@ -1009,12 +1032,13 @@ static ir::ScriptFunction *GetWrappingLambdaParentFunction(public_lib::Context * ir::FunctionSignature {nullptr, std::move(params), allocator->New(signature->ReturnType(), allocator)}, ir::ScriptFunctionFlags::ARROW}); - + ES2PANDA_ASSERT(func != nullptr); ArenaVector bodyStmts {allocator->Adapter()}; ArenaVector callArgs {allocator->Adapter()}; for (auto *p : func->Params()) { ir::Identifier *clone = p->AsETSParameterExpression()->Ident()->Clone(allocator, nullptr); + ES2PANDA_ASSERT(clone != nullptr); if (clone->IsIdentifier() && (clone->IsReference(ScriptExtension::ETS)) && (clone->TypeAnnotation() != nullptr)) { clone->SetTsTypeAnnotation(nullptr); @@ -1159,7 +1183,7 @@ static bool IsFunctionOrMethodCall(checker::ETSChecker *checker, ir::CallExpress // Not skip if invoke pattern Union.() where field is of ETSArrowType if (callee->IsMemberExpression()) { auto me = callee->AsMemberExpression(); - ES2PANDA_ASSERT(me->TsType()); + ES2PANDA_ASSERT(me->TsType() != nullptr); if (me->Object()->TsType() != nullptr && checker->GetApparentType(me->Object()->TsType())->IsETSUnionType() && me->TsType()->IsETSMethodType()) { return true; @@ -1185,10 +1209,12 @@ static ir::AstNode *InsertInvokeCall(public_lib::Context *ctx, ir::CallExpressio auto *oldCallee = call->Callee(); auto *oldType = checker->GetApparentType(oldCallee->TsType()); + ES2PANDA_ASSERT(oldType != nullptr); size_t arity = call->Arguments().size(); auto *ifaceType = oldType->IsETSObjectType() ? oldType->AsETSObjectType() : oldType->AsETSFunctionType()->ArrowToFunctionalInterfaceDesiredArity(checker, arity); + ES2PANDA_ASSERT(ifaceType != nullptr); if (ifaceType->IsETSDynamicType()) { return call; } @@ -1200,12 +1226,13 @@ static ir::AstNode *InsertInvokeCall(public_lib::Context *ctx, ir::CallExpressio checker::PropertySearchFlags::SEARCH_IN_INTERFACES); ES2PANDA_ASSERT(prop != nullptr); auto *invoke0Id = allocator->New(invokeMethodName, allocator); - ES2PANDA_ASSERT(invoke0Id); + ES2PANDA_ASSERT(invoke0Id != nullptr); invoke0Id->SetTsType(prop->TsType()); invoke0Id->SetVariable(prop); auto *newCallee = util::NodeAllocator::ForceSetParent( allocator, oldCallee, invoke0Id, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); + ES2PANDA_ASSERT(newCallee != nullptr); newCallee->SetTsType(prop->TsType()); newCallee->SetObjectType(ifaceType); diff --git a/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp b/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp index 8951849eec..f8c01f4856 100644 --- a/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp +++ b/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp @@ -1017,6 +1017,7 @@ void TSDeclGen::GenAnnotationProperties(const ir::AnnotationUsage *anno) OutEndlDts(); for (auto *prop : properties) { ProcessIndent(); + ES2PANDA_ASSERT(prop->AsClassProperty()->Id() != nullptr); OutDts(prop->AsClassProperty()->Id()->Name()); OutDts(": "); if (prop->AsClassProperty()->Value() != nullptr) { @@ -2059,6 +2060,7 @@ bool TSDeclGen::GenMethodDeclarationPrefix(const ir::MethodDefinition *methodDef } EmitMethodGlueCode(methodName, methodIdent); + ES2PANDA_ASSERT(methodDef->Function() != nullptr); if (methodDef->Function()->IsAbstract() && !state_.inInterface && !(methodDef->Parent()->IsTSInterfaceBody() || (methodDef->BaseOverloadMethod() != nullptr && diff --git a/ets2panda/ir/ets/etsNeverType.cpp b/ets2panda/ir/ets/etsNeverType.cpp index 5139f9c4fe..60e6dd2d8c 100644 --- a/ets2panda/ir/ets/etsNeverType.cpp +++ b/ets2panda/ir/ets/etsNeverType.cpp @@ -73,7 +73,7 @@ checker::Type *ETSNeverType::GetType([[maybe_unused]] checker::ETSChecker *check ETSNeverType *ETSNeverType::Clone(ArenaAllocator *allocator, AstNode *parent) { auto *const clone = allocator->New(allocator); - ES2PANDA_ASSERT(clone); + ES2PANDA_ASSERT(clone != nullptr); if (parent != nullptr) { clone->SetParent(parent); @@ -82,7 +82,9 @@ ETSNeverType *ETSNeverType::Clone(ArenaAllocator *allocator, AstNode *parent) if (!Annotations().empty()) { ArenaVector annotationUsages {allocator->Adapter()}; for (auto *annotationUsage : Annotations()) { - annotationUsages.push_back(annotationUsage->Clone(allocator, clone)->AsAnnotationUsage()); + auto *const annotationClone = annotationUsage->Clone(allocator, clone); + ES2PANDA_ASSERT(annotationClone != nullptr); + annotationUsages.push_back(annotationClone->AsAnnotationUsage()); } clone->SetAnnotations(std::move(annotationUsages)); } diff --git a/ets2panda/ir/ets/etsParameterExpression.cpp b/ets2panda/ir/ets/etsParameterExpression.cpp index 4f1f375369..a608353406 100644 --- a/ets2panda/ir/ets/etsParameterExpression.cpp +++ b/ets2panda/ir/ets/etsParameterExpression.cpp @@ -233,8 +233,16 @@ checker::VerifiedType ETSParameterExpression::Check(checker::ETSChecker *const c ETSParameterExpression *ETSParameterExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const identOrSpread = spread_ != nullptr ? spread_->Clone(allocator, nullptr)->AsAnnotatedExpression() - : ident_->Clone(allocator, nullptr)->AsAnnotatedExpression(); + AnnotatedExpression *identOrSpread = nullptr; + if (spread_ != nullptr) { + auto spreadClone = spread_->Clone(allocator, nullptr); + ES2PANDA_ASSERT(spreadClone != nullptr); + identOrSpread = spreadClone->AsAnnotatedExpression(); + } else { + auto identClone = ident_->Clone(allocator, nullptr); + ES2PANDA_ASSERT(identClone != nullptr); + identOrSpread = identClone->AsAnnotatedExpression(); + } auto *const initializer = initializer_ != nullptr ? initializer_->Clone(allocator, nullptr)->AsExpression() : nullptr; @@ -247,7 +255,7 @@ ETSParameterExpression *ETSParameterExpression::Clone(ArenaAllocator *const allo initializer->SetParent(clone); } - ES2PANDA_ASSERT(clone); + ES2PANDA_ASSERT(clone != nullptr); if (parent != nullptr) { clone->SetParent(parent); } @@ -257,7 +265,9 @@ ETSParameterExpression *ETSParameterExpression::Clone(ArenaAllocator *const allo if (!Annotations().empty()) { ArenaVector annotationUsages {allocator->Adapter()}; for (auto *annotationUsage : Annotations()) { - annotationUsages.push_back(annotationUsage->Clone(allocator, clone)->AsAnnotationUsage()); + auto *const annotationClone = annotationUsage->Clone(allocator, clone); + ES2PANDA_ASSERT(annotationClone != nullptr); + annotationUsages.push_back(annotationClone->AsAnnotationUsage()); } clone->SetAnnotations(std::move(annotationUsages)); } diff --git a/ets2panda/ir/ets/etsPrimitiveType.cpp b/ets2panda/ir/ets/etsPrimitiveType.cpp index 58f800f0ab..5ef99da421 100644 --- a/ets2panda/ir/ets/etsPrimitiveType.cpp +++ b/ets2panda/ir/ets/etsPrimitiveType.cpp @@ -159,6 +159,7 @@ checker::Type *ETSPrimitiveType::GetType([[maybe_unused]] checker::ETSChecker *c ETSPrimitiveType *ETSPrimitiveType::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const clone = allocator->New(type_, allocator); + ES2PANDA_ASSERT(clone != nullptr); if (parent != nullptr) { clone->SetParent(parent); @@ -167,8 +168,9 @@ ETSPrimitiveType *ETSPrimitiveType::Clone(ArenaAllocator *const allocator, AstNo if (!Annotations().empty()) { ArenaVector annotationUsages {allocator->Adapter()}; for (auto *annotationUsage : Annotations()) { - ES2PANDA_ASSERT(annotationUsage->Clone(allocator, clone)); - annotationUsages.push_back(annotationUsage->Clone(allocator, clone)->AsAnnotationUsage()); + auto *annotationClone = annotationUsage->Clone(allocator, clone); + ES2PANDA_ASSERT(annotationClone != nullptr); + annotationUsages.push_back(annotationClone->AsAnnotationUsage()); } clone->SetAnnotations(std::move(annotationUsages)); } diff --git a/ets2panda/ir/ets/etsTuple.cpp b/ets2panda/ir/ets/etsTuple.cpp index 8de5db97f1..c00faf8339 100644 --- a/ets2panda/ir/ets/etsTuple.cpp +++ b/ets2panda/ir/ets/etsTuple.cpp @@ -138,7 +138,7 @@ checker::Type *ETSTuple::GetType(checker::ETSChecker *const checker) ETSTuple *ETSTuple::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const clone = allocator->New(allocator, size_); - ES2PANDA_ASSERT(clone); + ES2PANDA_ASSERT(clone != nullptr); clone->AddModifier(flags_); @@ -155,7 +155,9 @@ ETSTuple *ETSTuple::Clone(ArenaAllocator *const allocator, AstNode *const parent if (!Annotations().empty()) { ArenaVector annotationUsages {allocator->Adapter()}; for (auto *annotationUsage : Annotations()) { - annotationUsages.push_back(annotationUsage->Clone(allocator, clone)->AsAnnotationUsage()); + auto *const annotationClone = annotationUsage->Clone(allocator, clone); + ES2PANDA_ASSERT(annotationClone != nullptr); + annotationUsages.push_back(annotationClone->AsAnnotationUsage()); } clone->SetAnnotations(std::move(annotationUsages)); } diff --git a/ets2panda/ir/ets/etsTypeReference.cpp b/ets2panda/ir/ets/etsTypeReference.cpp index 21db7e1814..bcad213c61 100644 --- a/ets2panda/ir/ets/etsTypeReference.cpp +++ b/ets2panda/ir/ets/etsTypeReference.cpp @@ -112,8 +112,14 @@ checker::Type *ETSTypeReference::GetType(checker::ETSChecker *checker) ETSTypeReference *ETSTypeReference::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const partClone = part_ != nullptr ? part_->Clone(allocator, nullptr)->AsETSTypeReferencePart() : nullptr; + ETSTypeReferencePart *partClone = nullptr; + if (part_ != nullptr) { + auto *const clone = part_->Clone(allocator, nullptr)->AsETSTypeReferencePart(); + ES2PANDA_ASSERT(clone != nullptr); + partClone = clone->AsETSTypeReferencePart(); + } auto *const clone = allocator->New(partClone, allocator); + ES2PANDA_ASSERT(clone != nullptr); if (partClone != nullptr) { partClone->SetParent(clone); @@ -128,7 +134,9 @@ ETSTypeReference *ETSTypeReference::Clone(ArenaAllocator *const allocator, AstNo if (!Annotations().empty()) { ArenaVector annotationUsages {allocator->Adapter()}; for (auto *annotationUsage : Annotations()) { - annotationUsages.push_back(annotationUsage->Clone(allocator, clone)->AsAnnotationUsage()); + auto *annotationClone = annotationUsage->Clone(allocator, clone); + ES2PANDA_ASSERT(annotationClone != nullptr); + annotationUsages.push_back(annotationClone->AsAnnotationUsage()); } clone->SetAnnotations(std::move(annotationUsages)); } -- Gitee