@@ -861,27 +861,55 @@ pub fn import_package_path(
861861 None
862862}
863863
864+ /// Whether `scope` is a container `import` is declared directly under, i.e. the
865+ /// point the import-visibility walk stops at.
866+ fn is_import_container ( scope : ScopeId ) -> bool {
867+ SCOPE_ARENA . with ( |f| {
868+ f. borrow ( ) . scopes . get ( scope. 0 as usize ) . is_some_and ( |s| {
869+ matches ! (
870+ s. kind,
871+ ScopeKind :: Module | ScopeKind :: Interface | ScopeKind :: Package
872+ )
873+ } )
874+ } )
875+ }
876+
864877/// Whether `symbol` (named `name`, declared under `symbol_define_context`) is
865- /// imported directly into `namespace`, matching its exact paths and ifdef
866- /// context. Wildcard members are additionally gated by the source container's
867- /// ifdef context, mirroring the resolver's `Tier 2` wildcard visibility so an
878+ /// imported into `namespace`, matching its exact paths and ifdef context.
879+ /// Wildcard members are additionally gated by the source container's ifdef
880+ /// context, mirroring the resolver's `Tier 2` wildcard visibility so an
868881/// ifdef-excluded member is not treated as imported.
882+ ///
883+ /// An `import` under a module/interface/package takes effect across all of it,
884+ /// so a nested scope (generate block, function) also sees the bindings of the
885+ /// scopes enclosing it up to and including that container. The walk stops there
886+ /// because `import` is not visible across a container boundary.
869887pub fn is_imported (
870888 namespace : & Namespace ,
871889 symbol : SymbolId ,
872890 name : StrId ,
873891 symbol_define_context : & DefineContext ,
874892) -> bool {
875- let scope = intern_namespace ( namespace) ;
876893 let dctx = & namespace. define_context ;
877- imports_get ( scope, name)
878- . iter ( )
879- . any ( |b| b. symbol == symbol && & b. define_context == dctx)
880- || wildcards_get ( scope) . iter ( ) . any ( |w| {
881- & w. define_context == dctx
882- && !symbol_define_context. exclusive ( & w. source_define_context )
883- && locals_get ( w. source , name) . contains ( & symbol)
884- } )
894+ let mut current = Some ( intern_namespace ( namespace) ) ;
895+ while let Some ( scope) = current {
896+ let imported = imports_get ( scope, name)
897+ . iter ( )
898+ . any ( |b| b. symbol == symbol && & b. define_context == dctx)
899+ || wildcards_get ( scope) . iter ( ) . any ( |w| {
900+ & w. define_context == dctx
901+ && !symbol_define_context. exclusive ( & w. source_define_context )
902+ && locals_get ( w. source , name) . contains ( & symbol)
903+ } ) ;
904+ if imported {
905+ return true ;
906+ }
907+ if is_import_container ( scope) {
908+ break ;
909+ }
910+ current = parent ( scope) ;
911+ }
912+ false
885913}
886914
887915/// Returns the wildcard imports declared directly in `scope`.
0 commit comments