From 5a32e58e048aac3aa1d9ed686f7f178f8750220e Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Thu, 12 May 2022 13:40:57 -0700 Subject: [PATCH] fix bug that sometimes associated the wrong location with global statements --- src/parse.y | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/parse.y b/src/parse.y index ced76e6269..39046348b1 100644 --- a/src/parse.y +++ b/src/parse.y @@ -317,12 +317,22 @@ static StmtPtr build_local(ID* id, Type* t, InitClass ic, Expr* e, %% zeek: - decl_list stmt_list + decl_list + { + // Without the following, in some scenarios the + // location associated with global statements gets + // associated with the last @load'd file rather than + // the script that includes the global statements. + auto loc = zeek::detail::GetCurrentLocation(); + if ( loc.filename ) + set_location(loc); + } + stmt_list { if ( stmts ) - stmts->AsStmtList()->Stmts().push_back($2); + stmts->AsStmtList()->Stmts().push_back($3); else - stmts = $2; + stmts = $3; // Any objects creates from here on out should not // have file positions associated with them.