From f4d55081ed7053b777617542fd5ac3f607268ff0 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 25 Sep 2022 19:00:46 +0200 Subject: [PATCH] Don't allow access to imported identifiers through hierarchical names Imported identifiers should only be visible in the scope they have been imported too. They should not be accessible through hierarchical names into that scope. This is defined in section 26.3 ("Referencing data in packages") of the LRM (1800-2017). Modify the symbol search to not look at imports if the name is part of a hierarchical path. Signed-off-by: Lars-Peter Clausen --- symbol_search.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/symbol_search.cc b/symbol_search.cc index 2b6cc707f..b7e3df15b 100644 --- a/symbol_search.cc +++ b/symbol_search.cc @@ -202,11 +202,6 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, } } - if (NetScope*import_scope = scope->find_import(des, path_tail.name)) { - scope = import_scope; - continue; - } - // Could not find an object. Maybe this is a child scope name? If // so, evaluate the path components to find the exact scope this // refers to. This item might be: @@ -234,6 +229,12 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, if (prefix_scope) break; + // Imports are not visible through hierachical names + if (NetScope*import_scope = scope->find_import(des, path_tail.name)) { + scope = import_scope; + continue; + } + // Special case: We can match the module name of a parent // module. That means if the current scope is a module of type // "mod", then "mod" matches the current scope. This is fairly