@@ -299,13 +299,18 @@ static bool AreSameDerivedType(const semantics::DerivedTypeSpec &,
299
299
300
300
// F2023 7.5.3.2
301
301
static bool AreSameComponent (const semantics::Symbol &x,
302
- const semantics::Symbol &y, bool ignoreSequence,
302
+ const semantics::Symbol &y, bool ignoreSequence, bool sameModuleName,
303
303
SetOfDerivedTypePairs &inProgress) {
304
304
if (x.attrs () != y.attrs ()) {
305
305
return false ;
306
306
}
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
+ }
309
314
}
310
315
if (x.size () && y.size ()) {
311
316
if (x.offset () != y.offset () || x.size () != y.size ()) {
@@ -482,9 +487,20 @@ static bool AreSameDerivedType(const semantics::DerivedTypeSpec &x,
482
487
ySymbol.attrs ().test (semantics::Attr::BIND_C)) {
483
488
return false ;
484
489
}
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)) {
488
504
// PGI does not enforce this requirement; all other Fortran
489
505
// compilers do with a hard error when violations are caught.
490
506
return false ;
@@ -502,9 +518,10 @@ static bool AreSameDerivedType(const semantics::DerivedTypeSpec &x,
502
518
const auto xLookup{xSymbol.scope ()->find (*xComponentName)};
503
519
const auto yLookup{ySymbol.scope ()->find (*yComponentName)};
504
520
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)) {
508
525
return false ;
509
526
}
510
527
}
@@ -576,17 +593,15 @@ static bool AreCompatibleTypes(const DynamicType &x, const DynamicType &y,
576
593
const auto yLen{y.knownLength ()};
577
594
return x.kind () == y.kind () &&
578
595
(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) {
586
597
const auto *xdt{GetDerivedTypeSpec (x)};
587
598
const auto *ydt{GetDerivedTypeSpec (y)};
588
599
return AreCompatibleDerivedTypes (
589
600
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 ();
590
605
}
591
606
}
592
607
0 commit comments