File tree Expand file tree Collapse file tree 2 files changed +46
-3
lines changed Expand file tree Collapse file tree 2 files changed +46
-3
lines changed Original file line number Diff line number Diff line change @@ -608,8 +608,25 @@ MaybeExpr ExpressionAnalyzer::Analyze(const parser::Designator &d) {
608608 dataRef = ExtractDataRef (std::move (result),
609609 /* intoSubstring=*/ false , /* intoComplexPart=*/ true );
610610 }
611- if (dataRef && !CheckDataRef (*dataRef)) {
612- result.reset ();
611+ if (dataRef) {
612+ if (!CheckDataRef (*dataRef)) {
613+ result.reset ();
614+ } else if (ExtractCoarrayRef (*dataRef).has_value ()) {
615+ if (auto dyType{result->GetType ()};
616+ dyType && dyType->category () == TypeCategory::Derived) {
617+ if (!std::holds_alternative<CoarrayRef>(dataRef->u ) &&
618+ dyType->IsPolymorphic ()) { // F'2023 C918
619+ Say (" The base of a polymorphic object may not be coindexed" _err_en_US);
620+ }
621+ if (const auto *derived{GetDerivedTypeSpec (*dyType)}) {
622+ if (auto bad{FindPolymorphicAllocatablePotentialComponent (
623+ *derived)}) { // F'2023 C917
624+ Say (" A coindexed designator may not have a type with the polymorphic potential subobject component '%s'" _err_en_US,
625+ bad.BuildResultDesignatorName ());
626+ }
627+ }
628+ }
629+ }
613630 }
614631 }
615632 return result;
Original file line number Diff line number Diff line change 11! RUN: %python %S/test_errors.py %s %flang_fc1
22! More coarray error tests.
3- module m
3+ module m1
44 integer :: local[* ] ! ok in module
55end
66program main
@@ -48,3 +48,29 @@ function func2()
4848 ! ERROR: Local variable 'local' without the SAVE or ALLOCATABLE attribute may not have a coarray potential subobject component '%comp'
4949 type (t) :: local
5050end
51+
52+ module m2
53+ type t0
54+ integer n
55+ end type
56+ type t1
57+ class(t0), allocatable :: a
58+ end type
59+ type t2
60+ type (t1) c
61+ end type
62+ contains
63+ subroutine test (x )
64+ type (t2), intent (in ) :: x[* ]
65+ ! ERROR: The base of a polymorphic object may not be coindexed
66+ call sub1(x[1 ]% c% a)
67+ ! ERROR: A coindexed designator may not have a type with the polymorphic potential subobject component '%a'
68+ call sub2(x[1 ]% c)
69+ end
70+ subroutine sub1 (x )
71+ type (t0), intent (in ) :: x
72+ end
73+ subroutine sub2 (x )
74+ type (t1), intent (in ) :: x
75+ end
76+ end
You can’t perform that action at this time.
0 commit comments