Question Regarding Hierarchical References

Hi all,

After reading LRM sections 23.7–23.9, I have a few questions about the concept of hierarchical references.

Q1.

int i = 8;
module tb;
  initial begin: init_blk
    $display("i: %0d", i);
  end
endmodule

According to LRM Chapter 23.9: “If an identifier is referenced directly (without a hierarchical path)… If the item is a variable, it shall stop at a module boundary.”
So the search should stop once it reaches module tb. But in practice, the variable i can still be referenced. What is meant by “module boundary” in this context?

Q2.

interface intf;
  int i = 8;
endinterface

module tb;
  initial begin: init_blk
    $display("i: %0d", intf.i);
  end
endmodule

According to LRM Chapter 23.9: “If an identifier is referenced with a hierarchical name, the path can start with a module name, interface name…”.
In my case, I used the interface name intf, but the compiler still reports an error.

Q3.

Based on the rules and examples in LRM Chapter 23.8 Upwards Name Referencing, it appears that scope_name in a hierarchical reference can be a module name only when it refers to the module containing the statement. In all other cases, only instance names are allowed, and item_name always refers to an instance name. Is my understanding of this correct?

Also, based on my understanding, the search first proceeds in the declaration scope until it reaches the design element scope, and then it continues in the scope where the module is instantiated. Does this mean the lookup alternates between the declaration scope and the instantiation scope?

BR,
Boris

This section of the LRM has several issues, some of which are listed below.

A1: The declaration in i is in the compilation unit ($unit), which is treated like an implicit package import from the compilation unit. See Section. 3.12.1 Compilation unit. Other sections of the LRM were never updated to deal with this functionality.

A2: You need to read the sentence that follows the one you quoted. The names shall be searched first at the current level and then in higher level modules until found.
In your example, tb at the highest level. Modules and interfaces are not part of $unit

A3. No, scope_name is always a module (or interface) name in either the module in which the reference appears or at an upper hierarchical level. item_name is almost any identifier you’ve declared except for type names.