@@ -293,11 +293,13 @@ using SetOfDerivedTypePairs =
293293
294294static bool AreSameDerivedType (const semantics::DerivedTypeSpec &,
295295 const semantics::DerivedTypeSpec &, bool ignoreTypeParameterValues,
296- bool ignoreLenParameters, SetOfDerivedTypePairs &inProgress);
296+ bool ignoreLenParameters, bool ignoreSequence,
297+ SetOfDerivedTypePairs &inProgress);
297298
298299// F2023 7.5.3.2
299300static bool AreSameComponent (const semantics::Symbol &x,
300- const semantics::Symbol &y, SetOfDerivedTypePairs &inProgress) {
301+ const semantics::Symbol &y, bool ignoreSequence,
302+ SetOfDerivedTypePairs &inProgress) {
301303 if (x.attrs () != y.attrs ()) {
302304 return false ;
303305 }
@@ -325,7 +327,8 @@ static bool AreSameComponent(const semantics::Symbol &x,
325327 !yType->IsUnlimitedPolymorphic () ||
326328 (!xType->IsUnlimitedPolymorphic () &&
327329 !AreSameDerivedType (xType->GetDerivedTypeSpec (),
328- yType->GetDerivedTypeSpec (), false , false , inProgress))) {
330+ yType->GetDerivedTypeSpec (), false , false , ignoreSequence,
331+ inProgress))) {
329332 return false ;
330333 }
331334 } else if (!xType->IsTkLenCompatibleWith (*yType)) {
@@ -449,7 +452,8 @@ static bool AreTypeParamCompatible(const semantics::DerivedTypeSpec &x,
449452// F2023 7.5.3.2
450453static bool AreSameDerivedType (const semantics::DerivedTypeSpec &x,
451454 const semantics::DerivedTypeSpec &y, bool ignoreTypeParameterValues,
452- bool ignoreLenParameters, SetOfDerivedTypePairs &inProgress) {
455+ bool ignoreLenParameters, bool ignoreSequence,
456+ SetOfDerivedTypePairs &inProgress) {
453457 if (&x == &y) {
454458 return true ;
455459 }
@@ -472,7 +476,12 @@ static bool AreSameDerivedType(const semantics::DerivedTypeSpec &x,
472476 inProgress.insert (thisQuery);
473477 const auto &xDetails{xSymbol.get <semantics::DerivedTypeDetails>()};
474478 const auto &yDetails{ySymbol.get <semantics::DerivedTypeDetails>()};
475- if (!(xDetails.sequence () && yDetails.sequence ()) &&
479+ if (xDetails.sequence () != yDetails.sequence () ||
480+ xSymbol.attrs ().test (semantics::Attr::BIND_C) !=
481+ ySymbol.attrs ().test (semantics::Attr::BIND_C)) {
482+ return false ;
483+ }
484+ if (!ignoreSequence && !(xDetails.sequence () && yDetails.sequence ()) &&
476485 !(xSymbol.attrs ().test (semantics::Attr::BIND_C) &&
477486 ySymbol.attrs ().test (semantics::Attr::BIND_C))) {
478487 // PGI does not enforce this requirement; all other Fortran
@@ -493,7 +502,8 @@ static bool AreSameDerivedType(const semantics::DerivedTypeSpec &x,
493502 const auto yLookup{ySymbol.scope ()->find (*yComponentName)};
494503 if (xLookup == xSymbol.scope ()->end () ||
495504 yLookup == ySymbol.scope ()->end () ||
496- !AreSameComponent (*xLookup->second , *yLookup->second , inProgress)) {
505+ !AreSameComponent (
506+ *xLookup->second , *yLookup->second , ignoreSequence, inProgress)) {
497507 return false ;
498508 }
499509 }
@@ -503,13 +513,19 @@ static bool AreSameDerivedType(const semantics::DerivedTypeSpec &x,
503513bool AreSameDerivedType (
504514 const semantics::DerivedTypeSpec &x, const semantics::DerivedTypeSpec &y) {
505515 SetOfDerivedTypePairs inProgress;
506- return AreSameDerivedType (x, y, false , false , inProgress);
516+ return AreSameDerivedType (x, y, false , false , false , inProgress);
507517}
508518
509519bool AreSameDerivedTypeIgnoringTypeParameters (
510520 const semantics::DerivedTypeSpec &x, const semantics::DerivedTypeSpec &y) {
511521 SetOfDerivedTypePairs inProgress;
512- return AreSameDerivedType (x, y, true , true , inProgress);
522+ return AreSameDerivedType (x, y, true , true , false , inProgress);
523+ }
524+
525+ bool AreSameDerivedTypeIgnoringSequence (
526+ const semantics::DerivedTypeSpec &x, const semantics::DerivedTypeSpec &y) {
527+ SetOfDerivedTypePairs inProgress;
528+ return AreSameDerivedType (x, y, false , false , true , inProgress);
513529}
514530
515531static bool AreSameDerivedType (
@@ -536,7 +552,7 @@ static bool AreCompatibleDerivedTypes(const semantics::DerivedTypeSpec *x,
536552 } else {
537553 SetOfDerivedTypePairs inProgress;
538554 if (AreSameDerivedType (*x, *y, ignoreTypeParameterValues,
539- ignoreLenTypeParameters, inProgress)) {
555+ ignoreLenTypeParameters, false , inProgress)) {
540556 return true ;
541557 } else {
542558 return isPolymorphic &&
0 commit comments