From da0adf66142d86505e6070ab90d19672b31fc131 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 2 Aug 2026 10:23:10 -0700 Subject: [PATCH] Avoid comparing lexical positions across units for package imports Package imports already resolve names declared in packages from other compilation units. After `NetScope::find_import()` finds such an import, however, `symbol_search()` continues with an unbound lookup. It then compares the declaration position in the package with the reference position in the importing unit. Lexical positions are local to a compilation unit, so these unrelated values can make a legal imported variable, named event, or parameter appear to be used before its declaration. Set `scope_is_bound` after `NetScope::find_import()` has checked that the import is visible at the reference. The import already identifies the package that declares the name, so binding the search avoids the invalid cross-unit comparison and prevents lookup from continuing outside that package. Signed-off-by: Lars-Peter Clausen --- symbol_search.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/symbol_search.cc b/symbol_search.cc index e9c383fee..fc82cea9b 100644 --- a/symbol_search.cc +++ b/symbol_search.cc @@ -374,7 +374,11 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, // Imports are not visible through hierachical names if (auto import_scope = scope->find_import( des, path_tail.name, lexical_pos)) { + // The import binds the name to the returned package. Continue + // with the search bound to it, since lexical positions are + // unit-local. scope = import_scope; + scope_is_bound = true; continue; }