From 3053e9b8b4af4981ce5e3494b531c07c850f692f Mon Sep 17 00:00:00 2001 From: liyue Date: Tue, 2 Sep 2025 02:14:45 +0800 Subject: [PATCH] Add invalid return Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICVV0J Signed-off-by: liyue Change-Id: I8e9ea42033bd8ce9e90c2f743575e3657245a688 --- es2panda/compiler/function/functionBuilder.cpp | 5 +++++ es2panda/ir/base/scriptFunction.h | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/es2panda/compiler/function/functionBuilder.cpp b/es2panda/compiler/function/functionBuilder.cpp index fda570ed4f..088997deda 100644 --- a/es2panda/compiler/function/functionBuilder.cpp +++ b/es2panda/compiler/function/functionBuilder.cpp @@ -62,6 +62,11 @@ void FunctionBuilder::ImplicitReturn(const ir::AstNode *node) const } pg_->NotifyConcurrentResult(node); + if (node->Parent() && node->Parent()->IsScriptFunction() && + node->Parent()->AsScriptFunction()->IsGeneratedConstructor()) { + pg_->EmitReturn(node); + return; + } pg_->SetSourceLocationFlag(lexer::SourceLocationFlag::VALID_SOURCE_LOCATION); pg_->EmitReturn(node); } diff --git a/es2panda/ir/base/scriptFunction.h b/es2panda/ir/base/scriptFunction.h index f311f0d8da..f28d585969 100644 --- a/es2panda/ir/base/scriptFunction.h +++ b/es2panda/ir/base/scriptFunction.h @@ -151,6 +151,11 @@ public: (flags_ & ir::ScriptFunctionFlags::GENERATED_CONSTRUCTOR) != 0; } + bool IsGeneratedConstructor() const + { + return (flags_ & ir::ScriptFunctionFlags::GENERATED_CONSTRUCTOR) != 0; + } + bool IsStaticInitializer() const { return (flags_ & ir::ScriptFunctionFlags::STATIC_INITIALIZER) != 0; -- Gitee