From 53d430954583441fefc0ce83e3c44cb99ab44108 Mon Sep 17 00:00:00 2001 From: Klimentieva Date: Tue, 15 Jul 2025 17:38:04 +0300 Subject: [PATCH] codecheck fix dev branch Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICMKEK Change-Id: I501223b13011aa3849bd94637e5e1a470dce51ba Signed-off-by: Klimentieva --- .../ets/constantExpressionLowering.cpp | 1 + .../lowering/ets/declareOverloadLowering.cpp | 6 +- ...defaultParametersInConstructorLowering.cpp | 17 +++-- .../lowering/ets/genericBridgesLowering.cpp | 6 +- .../compiler/lowering/ets/lambdaLowering.cpp | 66 ++++++++++++------- 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, 99 insertions(+), 47 deletions(-) diff --git a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp index 6a08c07932..49f37059f0 100644 --- a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp +++ b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp @@ -1085,6 +1085,7 @@ static ir::AstNode *FoldLogicalUnaryExpression(const ir::UnaryExpression *unary, { auto resNode = util::NodeAllocator::Alloc(allocator, !TestLiteral(unary->Argument()->AsLiteral())); + ES2PANDA_ASSERT(resNode != nullptr); resNode->SetParent(const_cast(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 c65dccccc6..ad3cebeced 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->GetChecker()->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 3b7466ef9f..aef08af429 100644 --- a/ets2panda/compiler/lowering/ets/defaultParametersInConstructorLowering.cpp +++ b/ets2panda/compiler/lowering/ets/defaultParametersInConstructorLowering.cpp @@ -133,8 +133,8 @@ 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 | ir::ScriptFunctionFlags::SYNTHETIC); overloadMethod->SetRange(funcExpression->Range()); - ES2PANDA_ASSERT(overloadMethod->Function()); if (!method->IsDeclare() && method->Parent()->IsTSInterfaceBody()) { overloadMethod->Function()->Body()->AsBlockStatement()->ClearStatements(); } @@ -243,6 +245,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(); @@ -260,10 +263,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 e74ea9ce95..0c73ebec8c 100644 --- a/ets2panda/compiler/lowering/ets/genericBridgesLowering.cpp +++ b/ets2panda/compiler/lowering/ets/genericBridgesLowering.cpp @@ -85,9 +85,9 @@ void GenericBridgesPhase::AddGenericBridge(ir::ClassDefinition const *const clas 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 e4bd77c6fd..b5521581c5 100644 --- a/ets2panda/compiler/lowering/ets/lambdaLowering.cpp +++ b/ets2panda/compiler/lowering/ets/lambdaLowering.cpp @@ -95,6 +95,30 @@ 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 *checker = ctx->GetChecker()->AsETSChecker(); + auto *allocator = ctx->allocator; + 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) @@ -104,7 +128,6 @@ static std::pair CloneT } auto *allocator = ctx->allocator; - auto *checker = ctx->GetChecker()->AsETSChecker(); auto *newScope = allocator->New(allocator, enclosingScope); auto newTypeParams = ArenaVector(allocator->Adapter()); @@ -118,14 +141,14 @@ static std::pair CloneT 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 && newScope != nullptr && newTypeParamDecl != nullptr && + newTypeParamVar != nullptr); + newTypeParam->SetDeclNode(newTypeParamNode); + newTypeParamDecl->BindNode(newTypeParamNode); newTypeParamVar->SetTsType(newTypeParam); newScope->InsertBinding(newTypeParamId->Name(), newTypeParamVar); newTypeParamId->SetVariable(newTypeParamVar); @@ -137,23 +160,12 @@ static std::pair CloneT 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, std::move(substitution)}; @@ -167,6 +179,7 @@ inline static varbinder::Variable *InitNewParameterVariable(varbinder::VarBinder checker::Type *newParamType, varbinder::ParamScope *paramScope) { + ES2PANDA_ASSERT(param != nullptr); auto *var = varBinder->AddParamDecl(param); var->SetTsType(newParamType); var->SetScope(paramScope); @@ -202,7 +215,7 @@ 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); @@ -589,7 +602,7 @@ static ArenaVector CreateRestArgumentsArrayReall lciInfo->restParameterIdentifier, typeNode); } - ES2PANDA_ASSERT(args); + ES2PANDA_ASSERT(args != nullptr); return ArenaVector(args->AsBlockStatement()->Statements()); } @@ -600,9 +613,10 @@ static void CreateInvokeMethodRestParameter(public_lib::Context *ctx, LambdaClas auto *checker = ctx->GetChecker()->AsETSChecker(); auto *restIdent = Gensym(allocator); - ES2PANDA_ASSERT(restIdent); + ES2PANDA_ASSERT(restIdent != nullptr); lciInfo->restParameterIdentifier = restIdent->Name(); auto *spread = allocator->New(ir::AstNodeType::REST_ELEMENT, allocator, restIdent); + ES2PANDA_ASSERT(spread != nullptr); auto *restVar = lciInfo->lambdaSignature->RestVar(); auto *arr = (restVar != nullptr && restVar->TsType()->IsETSTupleType()) ? restVar->TsType() @@ -1167,12 +1181,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); @@ -1317,7 +1332,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; @@ -1344,10 +1359,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); bool hasRestParam = (oldType->IsETSFunctionType() && oldType->AsETSFunctionType()->ArrowSignature()->HasRestParameter()) || call->Signature()->HasRestParameter(); @@ -1358,12 +1375,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 bb99982b9a..497365674e 100644 --- a/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp +++ b/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp @@ -1005,6 +1005,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) { @@ -2047,6 +2048,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 0c0cbe895a..7b5041808f 100644 --- a/ets2panda/ir/ets/etsNeverType.cpp +++ b/ets2panda/ir/ets/etsNeverType.cpp @@ -68,7 +68,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); @@ -77,7 +77,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, nullptr); + 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 9292f3e75f..c24523fe04 100644 --- a/ets2panda/ir/ets/etsParameterExpression.cpp +++ b/ets2panda/ir/ets/etsParameterExpression.cpp @@ -271,8 +271,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; @@ -287,7 +295,7 @@ ETSParameterExpression *ETSParameterExpression::Clone(ArenaAllocator *const allo initializer->SetParent(clone); } - ES2PANDA_ASSERT(clone); + ES2PANDA_ASSERT(clone != nullptr); if (parent != nullptr) { clone->SetParent(parent); } @@ -297,7 +305,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, nullptr); + 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 cd4a16ccc6..8e538f9c65 100644 --- a/ets2panda/ir/ets/etsPrimitiveType.cpp +++ b/ets2panda/ir/ets/etsPrimitiveType.cpp @@ -154,6 +154,7 @@ checker::Type *ETSPrimitiveType::GetType([[maybe_unused]] checker::ETSChecker *c ETSPrimitiveType *ETSPrimitiveType::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const clone = allocator->New(GetPrimitiveType(), allocator); + ES2PANDA_ASSERT(clone != nullptr); if (parent != nullptr) { clone->SetParent(parent); @@ -162,8 +163,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, nullptr); + 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 968b287249..0a21e35971 100644 --- a/ets2panda/ir/ets/etsTuple.cpp +++ b/ets2panda/ir/ets/etsTuple.cpp @@ -131,7 +131,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_); @@ -148,7 +148,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, nullptr); + 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 5ad9abc912..e659e05474 100644 --- a/ets2panda/ir/ets/etsTypeReference.cpp +++ b/ets2panda/ir/ets/etsTypeReference.cpp @@ -126,8 +126,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); + ES2PANDA_ASSERT(clone != nullptr); + partClone = clone->AsETSTypeReferencePart(); + } auto *const clone = allocator->New(partClone, allocator); + ES2PANDA_ASSERT(clone != nullptr); if (partClone != nullptr) { partClone->SetParent(clone); @@ -142,7 +148,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, nullptr); + ES2PANDA_ASSERT(annotationClone != nullptr); + annotationUsages.push_back(annotationClone->AsAnnotationUsage()); } clone->SetAnnotations(std::move(annotationUsages)); } -- Gitee