@@ -299,13 +299,18 @@ static bool AreSameDerivedType(const semantics::DerivedTypeSpec &,
299299
300300// F2023 7.5.3.2
301301static bool AreSameComponent (const semantics::Symbol &x,
302- const semantics::Symbol &y, bool ignoreSequence,
302+ const semantics::Symbol &y, bool ignoreSequence, bool sameModuleName,
303303 SetOfDerivedTypePairs &inProgress) {
304304 if (x.attrs () != y.attrs ()) {
305305 return false ;
306306 }
307- if (x.attrs ().test (semantics::Attr::PRIVATE)) {
308- return false ;
307+ if (x.attrs ().test (semantics::Attr::PRIVATE) ||
308+ y.attrs ().test (semantics::Attr::PRIVATE)) {
309+ if (!sameModuleName ||
310+ x.attrs ().test (semantics::Attr::PRIVATE) !=
311+ y.attrs ().test (semantics::Attr::PRIVATE)) {
312+ return false ;
313+ }
309314 }
310315 if (x.size () && y.size ()) {
311316 if (x.offset () != y.offset () || x.size () != y.size ()) {
@@ -482,9 +487,20 @@ static bool AreSameDerivedType(const semantics::DerivedTypeSpec &x,
482487 ySymbol.attrs ().test (semantics::Attr::BIND_C)) {
483488 return false ;
484489 }
485- if (!ignoreSequence && !(xDetails.sequence () && yDetails.sequence ()) &&
486- !(xSymbol.attrs ().test (semantics::Attr::BIND_C) &&
487- ySymbol.attrs ().test (semantics::Attr::BIND_C))) {
490+ bool sameModuleName{false };
491+ const semantics::Scope &xOwner{xSymbol.owner ()};
492+ const semantics::Scope &yOwner{ySymbol.owner ()};
493+ if (xOwner.IsModule () && yOwner.IsModule ()) {
494+ if (auto xModuleName{xOwner.GetName ()}) {
495+ if (auto yModuleName{yOwner.GetName ()}) {
496+ if (*xModuleName == *yModuleName) {
497+ sameModuleName = true ;
498+ }
499+ }
500+ }
501+ }
502+ if (!sameModuleName && !ignoreSequence && !xDetails.sequence () &&
503+ !xSymbol.attrs ().test (semantics::Attr::BIND_C)) {
488504 // PGI does not enforce this requirement; all other Fortran
489505 // compilers do with a hard error when violations are caught.
490506 return false ;
@@ -502,9 +518,10 @@ static bool AreSameDerivedType(const semantics::DerivedTypeSpec &x,
502518 const auto xLookup{xSymbol.scope ()->find (*xComponentName)};
503519 const auto yLookup{ySymbol.scope ()->find (*yComponentName)};
504520 if (xLookup == xSymbol.scope ()->end () ||
505- yLookup == ySymbol.scope ()->end () ||
506- !AreSameComponent (
507- *xLookup->second , *yLookup->second , ignoreSequence, inProgress)) {
521+ yLookup == ySymbol.scope ()->end ()) {
522+ return false ;
523+ } else if (!AreSameComponent (*xLookup->second , *yLookup->second ,
524+ ignoreSequence, sameModuleName, inProgress)) {
508525 return false ;
509526 }
510527 }
@@ -576,17 +593,15 @@ static bool AreCompatibleTypes(const DynamicType &x, const DynamicType &y,
576593 const auto yLen{y.knownLength ()};
577594 return x.kind () == y.kind () &&
578595 (ignoreLengths || !xLen || !yLen || *xLen == *yLen);
579- } else if (x.category () != TypeCategory::Derived) {
580- if (x.IsTypelessIntrinsicArgument ()) {
581- return y.IsTypelessIntrinsicArgument ();
582- } else {
583- return !y.IsTypelessIntrinsicArgument () && x.kind () == y.kind ();
584- }
585- } else {
596+ } else if (x.category () == TypeCategory::Derived) {
586597 const auto *xdt{GetDerivedTypeSpec (x)};
587598 const auto *ydt{GetDerivedTypeSpec (y)};
588599 return AreCompatibleDerivedTypes (
589600 xdt, ydt, x.IsPolymorphic (), ignoreTypeParameterValues, false );
601+ } else if (x.IsTypelessIntrinsicArgument ()) {
602+ return y.IsTypelessIntrinsicArgument ();
603+ } else {
604+ return !y.IsTypelessIntrinsicArgument () && x.kind () == y.kind ();
590605 }
591606}
592607
0 commit comments