From d792d4fd0a3d1a432bfc590189ac4cede1b3bc96 Mon Sep 17 00:00:00 2001 From: Zhelyapov Aleksey Date: Fri, 11 Jul 2025 21:42:50 +0800 Subject: [PATCH] Fix codecheck Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICLS6Z Signed-off-by: Zhelyapov Aleksey --- ets2panda/compiler/core/ETSGen.cpp | 4 ++-- ets2panda/compiler/lowering/ets/enumLowering.cpp | 1 + .../lowering/ets/interfacePropertyDeclarations.cpp | 1 + ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp | 7 +++++-- ets2panda/varbinder/ETSBinder.cpp | 5 +++++ ets2panda/varbinder/scope.cpp | 2 ++ 6 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ets2panda/compiler/core/ETSGen.cpp b/ets2panda/compiler/core/ETSGen.cpp index 5b08e72fe6..0a724cf0d7 100644 --- a/ets2panda/compiler/core/ETSGen.cpp +++ b/ets2panda/compiler/core/ETSGen.cpp @@ -675,8 +675,7 @@ void ETSGen::BranchIfIsInstance(const ir::AstNode *const node, const VReg srcReg void ETSGen::IsInstance(const ir::AstNode *const node, const VReg srcReg, const checker::Type *target) { target = Checker()->GetApparentType(target); - ES2PANDA_ASSERT(target != nullptr); - ES2PANDA_ASSERT(target->IsETSReferenceType() && GetAccumulatorType() != nullptr); + ES2PANDA_ASSERT(target != nullptr && target->IsETSReferenceType() && GetAccumulatorType() != nullptr); if (target->IsETSAnyType()) { // should be IsSupertypeOf(target, source) LoadAccumulatorBoolean(node, true); @@ -1978,6 +1977,7 @@ static std::optional> SelectL ES2PANDA_ASSERT(alhs != nullptr && arhs != nullptr); alhs = alhs->IsETSStringType() ? checker->GlobalBuiltinETSStringType() : alhs; arhs = arhs->IsETSStringType() ? checker->GlobalBuiltinETSStringType() : arhs; + ES2PANDA_ASSERT(alhs != nullptr && arhs != nullptr); if (!alhs->IsETSObjectType() || !arhs->IsETSObjectType()) { return std::nullopt; } diff --git a/ets2panda/compiler/lowering/ets/enumLowering.cpp b/ets2panda/compiler/lowering/ets/enumLowering.cpp index 8db2e4c678..8a1fad31ae 100644 --- a/ets2panda/compiler/lowering/ets/enumLowering.cpp +++ b/ets2panda/compiler/lowering/ets/enumLowering.cpp @@ -345,6 +345,7 @@ void EnumLoweringPhase::CreateCCtorForEnumClass(ir::ClassDefinition *const enumC ir::ScriptFunctionFlags::STATIC_BLOCK | ir::ScriptFunctionFlags::HIDDEN, ir::ModifierFlags::STATIC, Language(Language::Id::ETS)}); + ES2PANDA_ASSERT(func != nullptr); func->SetIdent(id); id->SetParent(func); diff --git a/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp b/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp index c5a750ef45..7e8115aa06 100644 --- a/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp +++ b/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp @@ -78,6 +78,7 @@ ir::FunctionSignature InterfacePropertyDeclarationsPhase::GenerateGetterOrSetter if (isSetter) { auto paramIdent = field->Key()->AsIdentifier()->Clone(ctx->Allocator(), nullptr); + ES2PANDA_ASSERT(paramIdent != nullptr); paramIdent->SetTsTypeAnnotation(field->TypeAnnotation()->Clone(ctx->Allocator(), nullptr)); paramIdent->TypeAnnotation()->SetParent(paramIdent); diff --git a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp index 780c1346a8..94db1887d7 100644 --- a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp +++ b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp @@ -989,6 +989,7 @@ void InitScopesPhaseETS::DeclareClassMethod(ir::MethodDefinition *method) } const auto methodName = method->Id(); + ES2PANDA_ASSERT(methodName != nullptr); auto *const clsScope = VarBinder()->GetScope()->AsClassScope(); auto options = method->IsStatic() @@ -1029,8 +1030,9 @@ void InitScopesPhaseETS::MaybeAddOverload(ir::MethodDefinition *method, ir::Iden methodName->SetVariable(var); } for (auto *overload : method->Overloads()) { - ES2PANDA_ASSERT((overload->Function()->Flags() & ir::ScriptFunctionFlags::OVERLOAD) || - (overload->Function()->Flags() & ir::ScriptFunctionFlags::EXTERNAL_OVERLOAD)); + ES2PANDA_ASSERT(overload->Id() != nullptr && + ((overload->Function()->Flags() & ir::ScriptFunctionFlags::OVERLOAD) || + (overload->Function()->Flags() & ir::ScriptFunctionFlags::EXTERNAL_OVERLOAD))); overload->Id()->SetVariable(var); overload->SetParent(var->Declaration()->Node()); } @@ -1210,6 +1212,7 @@ void InitScopesPhaseETS::VisitMethodDefinition(ir::MethodDefinition *method) auto *curScope = VarBinder()->GetScope(); const auto methodName = method->Id(); + ES2PANDA_ASSERT(methodName != nullptr); auto res = curScope->Find(methodName->Name(), method->IsStatic() ? varbinder::ResolveBindingOptions::ALL_STATIC : varbinder::ResolveBindingOptions::ALL_NON_STATIC); diff --git a/ets2panda/varbinder/ETSBinder.cpp b/ets2panda/varbinder/ETSBinder.cpp index 2b9490bd7a..bc544f0631 100644 --- a/ets2panda/varbinder/ETSBinder.cpp +++ b/ets2panda/varbinder/ETSBinder.cpp @@ -345,6 +345,7 @@ void ETSBinder::ResolveInterfaceDeclaration(ir::TSInterfaceDeclaration *decl) auto fieldVar = ResolvePropertyReference(stmt->AsClassProperty(), decl->Scope()->AsClassScope()) ->FindLocal(stmt->AsClassProperty()->Id()->Name(), varbinder::ResolveBindingOptions::BINDINGS); + ES2PANDA_ASSERT(fieldVar != nullptr); fieldVar->AddFlag(VariableFlags::INITIALIZED); } @@ -418,6 +419,7 @@ void ETSBinder::ResolveMethodDefinition(ir::MethodDefinition *methodDef) methodDef->ResolveReferences([this](auto *childNode) { ResolveReference(childNode); }); auto *func = methodDef->Function(); + ES2PANDA_ASSERT(func != nullptr); for (auto *anno : func->Annotations()) { ResolveReference(anno); } @@ -597,6 +599,7 @@ void AddOverloadFlag(ArenaAllocator *allocator, bool isStdLib, varbinder::Variab ES2PANDA_ASSERT(method->Function() != nullptr); if (!method->Overloads().empty() && !method->HasOverload(currentNode)) { method->AddOverload(currentNode); + ES2PANDA_ASSERT(currentNode->Function() != nullptr); currentNode->Function()->Id()->SetVariable(importedVar); currentNode->Function()->AddFlag(ir::ScriptFunctionFlags::OVERLOAD); currentNode->Function()->AddFlag(ir::ScriptFunctionFlags::EXTERNAL_OVERLOAD); @@ -1497,6 +1500,7 @@ bool ETSBinder::ImportGlobalPropertiesForNotDefaultedExports(varbinder::Variable return true; } + ES2PANDA_ASSERT(classElement->Id() != nullptr); ThrowRedeclarationError(classElement->Id()->Start(), var, variable, name.Utf8()); } @@ -1509,6 +1513,7 @@ bool ETSBinder::ImportGlobalPropertiesForNotDefaultedExports(varbinder::Variable return true; } + ES2PANDA_ASSERT(classElement->Id() != nullptr); ThrowRedeclarationError(classElement->Id()->Start(), var, insRes.first->second, name.Utf8()); return false; } diff --git a/ets2panda/varbinder/scope.cpp b/ets2panda/varbinder/scope.cpp index efd86c2ee0..010ccd2e8a 100644 --- a/ets2panda/varbinder/scope.cpp +++ b/ets2panda/varbinder/scope.cpp @@ -1035,6 +1035,7 @@ void LoopDeclarationScope::ConvertToVariableScope(ArenaAllocator *allocator) slotIndex_++; loopType_ = ScopeType::LOOP_DECL; auto *copiedVar = var->AsLocalVariable()->Copy(allocator, var->Declaration()); + ES2PANDA_ASSERT(copiedVar != nullptr); copiedVar->AddFlag(VariableFlags::INITIALIZED | VariableFlags::PER_ITERATION); var->AddFlag(VariableFlags::LOOP_DECL); loopScope_->InsertBinding(name, copiedVar); @@ -1046,6 +1047,7 @@ void LoopDeclarationScope::ConvertToVariableScope(ArenaAllocator *allocator) slotIndex_ = std::max(slotIndex_, parentVarScope->LexicalSlots()); evalBindings_ = parentVarScope->EvalBindings(); initScope_ = allocator->New(allocator, Parent()); + ES2PANDA_ASSERT(initScope_ != nullptr); initScope_->BindNode(Node()); initScope_->MergeBindings(bindings); } -- Gitee