@@ -777,27 +777,55 @@ pub fn import_package_path(
777777 None
778778}
779779
780+ /// Whether `scope` is a container `import` is declared directly under, i.e. the
781+ /// point the import-visibility walk stops at.
782+ fn is_import_container ( scope : ScopeId ) -> bool {
783+ SCOPE_ARENA . with ( |f| {
784+ f. borrow ( ) . scopes . get ( scope. 0 as usize ) . is_some_and ( |s| {
785+ matches ! (
786+ s. kind,
787+ ScopeKind :: Module | ScopeKind :: Interface | ScopeKind :: Package
788+ )
789+ } )
790+ } )
791+ }
792+
780793/// Whether `symbol` (named `name`, declared under `symbol_define_context`) is
781- /// imported directly into `namespace`, matching its exact paths and ifdef
782- /// context. Wildcard members are additionally gated by the source container's
783- /// ifdef context, mirroring the resolver's `Tier 2` wildcard visibility so an
794+ /// imported into `namespace`, matching its exact paths and ifdef context.
795+ /// Wildcard members are additionally gated by the source container's ifdef
796+ /// context, mirroring the resolver's `Tier 2` wildcard visibility so an
784797/// ifdef-excluded member is not treated as imported.
798+ ///
799+ /// An `import` under a module/interface/package takes effect across all of it,
800+ /// so a nested scope (generate block, function) also sees the bindings of the
801+ /// scopes enclosing it up to and including that container. The walk stops there
802+ /// because `import` is not visible across a container boundary.
785803pub fn is_imported (
786804 namespace : & Namespace ,
787805 symbol : SymbolId ,
788806 name : StrId ,
789807 symbol_define_context : & DefineContext ,
790808) -> bool {
791- let scope = intern_namespace ( namespace) ;
792809 let dctx = & namespace. define_context ;
793- imports_get ( scope, name)
794- . iter ( )
795- . any ( |b| b. symbol == symbol && & b. define_context == dctx)
796- || wildcards_get ( scope) . iter ( ) . any ( |w| {
797- & w. define_context == dctx
798- && !symbol_define_context. exclusive ( & w. source_define_context )
799- && locals_get ( w. source , name) . contains ( & symbol)
800- } )
810+ let mut current = Some ( intern_namespace ( namespace) ) ;
811+ while let Some ( scope) = current {
812+ let imported = imports_get ( scope, name)
813+ . iter ( )
814+ . any ( |b| b. symbol == symbol && & b. define_context == dctx)
815+ || wildcards_get ( scope) . iter ( ) . any ( |w| {
816+ & w. define_context == dctx
817+ && !symbol_define_context. exclusive ( & w. source_define_context )
818+ && locals_get ( w. source , name) . contains ( & symbol)
819+ } ) ;
820+ if imported {
821+ return true ;
822+ }
823+ if is_import_container ( scope) {
824+ break ;
825+ }
826+ current = parent ( scope) ;
827+ }
828+ false
801829}
802830
803831/// Returns the wildcard imports declared directly in `scope`.
0 commit comments