diff --git a/es2panda/compiler/core/function.cpp b/es2panda/compiler/core/function.cpp index 98ec8de00793e16be310cc846cbb38edcf3ed877..4e73c94330ee3b892d366ee837e4a37c0c7b7a73 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 fda570ed4f975e4259a2850f25e0b0e43bcf32d2..f49ff4c05286c1d96b0d908ef9ae5aef3e9d6db7 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; }