diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 52d53589e51..802ae002ee2 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -1772,6 +1772,11 @@ check_constraint_info (tree t)
 #define DECL_MODULE_ENTITY_P(NODE) \
   (DECL_LANG_SPECIFIC (DECL_MODULE_CHECK (NODE))->u.base.module_entity_p)
 
+/* True if this decl was provided from a module partition, and should be
+   treated as-if it was declared in this TU.  */
+#define DECL_MODULE_PARTITION_P(NODE) \
+  (DECL_LANG_SPECIFIC (DECL_MODULE_CHECK (NODE))->u.base.module_partition_p)
+
 /* DECL that has attached decls for ODR-relatedness.  */
 #define DECL_MODULE_KEYED_DECLS_P(NODE) \
   (DECL_LANG_SPECIFIC (DECL_MODULE_CHECK (NODE))->u.base.module_keyed_decls_p)
@@ -2890,16 +2895,17 @@ struct GTY(()) lang_decl_base {
   unsigned var_declared_inline_p : 1;	   /* var */
   unsigned dependent_init_p : 1;	   /* var */
 
-  /* The following four apply to VAR, FUNCTION, TYPE, CONCEPT, & NAMESPACE
+  /* The following five apply to VAR, FUNCTION, TYPE, CONCEPT, & NAMESPACE
      decls.  */
   unsigned module_purview_p : 1;	   /* in named-module purview */
   unsigned module_attach_p : 1;		   /* attached to named module */
   unsigned module_import_p : 1;		   /* from an import */
   unsigned module_entity_p : 1;		   /* is in the entitity ary & hash */
+  unsigned module_partition_p : 1;	   /* imported from a partition */
 
   unsigned module_keyed_decls_p : 1;	   /* has keys, applies to all decls */
 
-  /* 11 spare bits.  */
+  /* 10 spare bits.  */
 };
 
 /* True for DECL codes which have template info and access.  */
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 8aab9ea0bae..29e2930485a 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -7650,6 +7650,11 @@ trees_in::install_entity (tree decl)
       slot = ident;
     }
 
+  if (state->is_partition ())
+    /* Remember that this came from a partition, even if we've seen it from a
+       non-partition before (e.g. for template instantiations).  */
+    DECL_MODULE_PARTITION_P (not_tmpl) = true;
+
   return true;
 }
 
@@ -12717,20 +12722,22 @@ depset::hash::make_dependency (tree decl, entity_kind ek)
 	  tree not_tmpl = STRIP_TEMPLATE (decl);
 
 	  if (DECL_LANG_SPECIFIC (not_tmpl)
-	      && DECL_MODULE_IMPORT_P (not_tmpl))
+	      && DECL_MODULE_IMPORT_P (not_tmpl)
+	      /* Treat entities imported from partitions as-if declared in
+		 this TU, unless we ourselves are also a partition.  */
+	      && (!DECL_MODULE_PARTITION_P (not_tmpl)
+		  || module_partition_p ()))
 	    {
 	      /* Store the module number and index in cluster/section,
 		 so we don't have to look them up again.  */
 	      unsigned index = import_entity_index (decl);
 	      module_state *from = import_entity_module (index);
 	      /* Remap will be zero for imports from partitions, which
-		 we want to treat as-if declared in this TU.  */
-	      if (from->remap)
-		{
-		  dep->cluster = index - from->entity_lwm;
-		  dep->section = from->remap;
-		  dep->set_flag_bit<DB_IMPORTED_BIT> ();
-		}
+		 should have been covered by the check above.  */
+	      gcc_assert (from->remap);
+	      dep->cluster = index - from->entity_lwm;
+	      dep->section = from->remap;
+	      dep->set_flag_bit<DB_IMPORTED_BIT> ();
 	    }
 
 	  if (ek == EK_DECL
diff --git a/gcc/testsuite/g++.dg/modules/pr99377-3_a.H b/gcc/testsuite/g++.dg/modules/pr99377-3_a.H
new file mode 100644
index 00000000000..580a7631ae1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr99377-3_a.H
@@ -0,0 +1,17 @@
+// { dg-additional-options "-fmodule-header" }
+// { dg-module-cmi {} }
+
+template<typename>
+struct Widget
+{
+  Widget (int) { }
+
+  bool First() const { return true; }
+
+  bool Second () const { return true;}
+};
+
+inline void Frob (const Widget<int>& w) noexcept
+{
+  w.First ();
+}
diff --git a/gcc/testsuite/g++.dg/modules/pr99377-3_b.C b/gcc/testsuite/g++.dg/modules/pr99377-3_b.C
new file mode 100644
index 00000000000..5cbce7b3544
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr99377-3_b.C
@@ -0,0 +1,10 @@
+// { dg-additional-options "-fmodules-ts" }
+// { dg-module-cmi Foo:check }
+
+export module Foo:check;
+import "pr99377-3_a.H";
+
+export inline bool Check (const Widget<int>& w)
+{
+  return w.Second ();
+}
diff --git a/gcc/testsuite/g++.dg/modules/pr99377-3_c.C b/gcc/testsuite/g++.dg/modules/pr99377-3_c.C
new file mode 100644
index 00000000000..fa7c24203bd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr99377-3_c.C
@@ -0,0 +1,5 @@
+// { dg-additional-options "-fmodules-ts" }
+// { dg-module-cmi Foo }
+
+export module Foo;
+export import :check;
diff --git a/gcc/testsuite/g++.dg/modules/pr99377-3_d.C b/gcc/testsuite/g++.dg/modules/pr99377-3_d.C
new file mode 100644
index 00000000000..cb1f28321b1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr99377-3_d.C
@@ -0,0 +1,8 @@
+// { dg-module-do link }
+// { dg-additional-options "-fmodules-ts" }
+
+import Foo;
+
+int main() {
+  return Check(0) ? 0 : 1;
+}
