diff --git a/ivtest/ivltests/sv_import_hier_fail1.v b/ivtest/ivltests/sv_import_hier_fail1.v new file mode 100644 index 000000000..7504d2e93 --- /dev/null +++ b/ivtest/ivltests/sv_import_hier_fail1.v @@ -0,0 +1,24 @@ +// Check that imported identifiers can't be accessed through hierarchical names. + +package P; + integer x; +endpackage + +module M; + import P::x; + integer y; + always_comb y = x; +endmodule + +module test; + + M m (); + + initial begin + integer y; + y = m.x; // This should fail. Imported identifiers are not visible through + // hierarchical names. + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_import_hier_fail2.v b/ivtest/ivltests/sv_import_hier_fail2.v new file mode 100644 index 000000000..be71fca59 --- /dev/null +++ b/ivtest/ivltests/sv_import_hier_fail2.v @@ -0,0 +1,24 @@ +// Check that imported identifiers can't be accessed through hierarchical names. + +package P; + integer x; +endpackage + +module M; + import P::*; + integer y; + always_comb y = x; +endmodule + +module test; + + M m (); + + initial begin + integer y; + y = m.x; // This should fail. Imported identifiers are not visible through + // hierarchical names. + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_import_hier_fail3.v b/ivtest/ivltests/sv_import_hier_fail3.v new file mode 100644 index 000000000..4db81ecad --- /dev/null +++ b/ivtest/ivltests/sv_import_hier_fail3.v @@ -0,0 +1,20 @@ +// Check that imported identifiers can't be accessed through hierarchical names. + +package P; + integer x; +endpackage + +module test; + + initial begin : outer + integer y; + begin: inner + import P::x; + y = x; + end + y = inner.x; // This should fail. Imported identifiers are not visible + // through hierarchical names. + $display("FAILED"); + end + +endmodule diff --git a/ivtest/regress-sv.list b/ivtest/regress-sv.list index 3ef2a144b..489239eab 100644 --- a/ivtest/regress-sv.list +++ b/ivtest/regress-sv.list @@ -656,6 +656,9 @@ sv_foreach8 normal,-g2009 ivltests gold=sv_foreach8.gold sv_foreach_fail1 CE,-g2009 ivltests sv_immediate_assert normal,-g2009 ivltests gold=sv_immediate_assert.gold sv_immediate_assume normal,-g2009 ivltests gold=sv_immediate_assume.gold +sv_import_hier_fail1 CE,-g2005-sv ivltests +sv_import_hier_fail2 CE,-g2005-sv ivltests +sv_import_hier_fail3 CE,-g2005-sv ivltests sv_macro normal,-g2009 ivltests sv_macro2 normal,-g2009 ivltests gold=sv_macro2.gold sv_macro3a normal,-g2009 ivltests gold=sv_macro3.gold 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