diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp --- a/flang/lib/Semantics/expression.cpp +++ b/flang/lib/Semantics/expression.cpp @@ -1089,15 +1089,17 @@ std::get>(x.imageSelector.t)) { std::visit( common::visitors{ - [&](const auto &x) {Analyze(x.v); }, + [&](const auto &x) { Analyze(x.v); }, }, imageSelSpec.u); } // Reverse the chain of symbols so that the base is first and coarray // ultimate component is last. - return Designate( - DataRef{CoarrayRef{SymbolVector{reversed.crbegin(), reversed.crend()}, - std::move(subscripts), std::move(cosubscripts)}}); + if (cosubsOk) { + return Designate( + DataRef{CoarrayRef{SymbolVector{reversed.crbegin(), reversed.crend()}, + std::move(subscripts), std::move(cosubscripts)}}); + } } return std::nullopt; } diff --git a/flang/test/Semantics/resolve94.f90 b/flang/test/Semantics/resolve94.f90 --- a/flang/test/Semantics/resolve94.f90 +++ b/flang/test/Semantics/resolve94.f90 @@ -13,6 +13,7 @@ integer, dimension(4) :: intArray integer :: intScalarCoarray[*] integer :: intCoarray[3, 4, *] + integer :: smallIntCoarray[4, *] intCoVar = 343 ! OK rVar1 = rCoarray[1,2,3] @@ -20,6 +21,8 @@ rVar1 = rCoarray[1,2] !ERROR: Must have INTEGER type, but is REAL(4) rVar1 = rCoarray[1,2,3.4] + !ERROR: Must have INTEGER type, but is REAL(4) + iVar1 = smallIntCoarray[3.4] !ERROR: Must be a scalar value, but is a rank-1 array rVar1 = rCoarray[1,intArray,3] ! OK