From 85e4744cd150e7306fde652ab75a611f72aaaf2d Mon Sep 17 00:00:00 2001 From: liyue Date: Fri, 5 Sep 2025 16:44:46 +0800 Subject: [PATCH] Adjust the line numbers for explicit constructors Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICWMBB Signed-off-by: liyue Change-Id: Ib4ca79eb41acf30651ca6b2492c5d46d2989750e --- es2panda/compiler/core/function.cpp | 5 +++++ es2panda/compiler/function/functionBuilder.cpp | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/es2panda/compiler/core/function.cpp b/es2panda/compiler/core/function.cpp index 98ec8de007..4e73c94330 100644 --- a/es2panda/compiler/core/function.cpp +++ b/es2panda/compiler/core/function.cpp @@ -171,8 +171,11 @@ static void CompileClassInitializer(PandaGen *pg, const ir::ScriptFunction *decl RegScope rs(pg); auto thisReg = pg->AllocReg(); + pg->SetSourceLocationFlag(lexer::SourceLocationFlag::INVALID_SOURCE_LOCATION); pg->GetThis(decl); pg->StoreAccumulator(decl, thisReg); + pg->SetSourceLocationFlag(lexer::SourceLocationFlag::VALID_SOURCE_LOCATION); + auto [level, slot] = pg->Scope()->Find(nullptr, true); if (!isStatic && classDef->HasInstancePrivateMethod()) { @@ -219,12 +222,14 @@ static void CompileFunction(PandaGen *pg) RegScope rs(pg); auto thisReg = pg->AllocReg(); + pg->SetSourceLocationFlag(lexer::SourceLocationFlag::INVALID_SOURCE_LOCATION); pg->GetThis(decl); pg->StoreAccumulator(decl, thisReg); auto [level, slot] = pg->Scope()->Find(classDef->InstanceInitializer()->Key()); pg->LoadLexicalVar(decl, level, slot); pg->CallInit(decl, thisReg); + pg->SetSourceLocationFlag(lexer::SourceLocationFlag::VALID_SOURCE_LOCATION); } } diff --git a/es2panda/compiler/function/functionBuilder.cpp b/es2panda/compiler/function/functionBuilder.cpp index fda570ed4f..f49ff4c052 100644 --- a/es2panda/compiler/function/functionBuilder.cpp +++ b/es2panda/compiler/function/functionBuilder.cpp @@ -50,8 +50,18 @@ void FunctionBuilder::ImplicitReturn(const ir::AstNode *node) const } pg_->LoadConst(node, Constant::JS_UNDEFINED); pg_->NotifyConcurrentResult(node); - pg_->SetSourceLocationFlag(lexer::SourceLocationFlag::VALID_SOURCE_LOCATION); - pg_->EmitReturnUndefined(node); + + // When no source location exists (e.g., in 'instance_initializer'), mark returnundefined as INVALID. + bool isEmptyRange = (node->Range().start.line == 0 && node->Range().end.line == 0 && + node->Range().start.index == 0 && node->Range().end.index == 0); + + if (isEmptyRange) { + pg_->EmitReturnUndefined(node); + pg_->SetSourceLocationFlag(lexer::SourceLocationFlag::VALID_SOURCE_LOCATION); + } else { + pg_->SetSourceLocationFlag(lexer::SourceLocationFlag::VALID_SOURCE_LOCATION); + pg_->EmitReturnUndefined(node); + } return; } -- Gitee