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 <lars@metafoo.de>
This commit is contained in:
parent
431b3ba1a2
commit
da0adf6614
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue