diff --git a/flang/lib/Evaluate/check-expression.cpp b/flang/lib/Evaluate/check-expression.cpp --- a/flang/lib/Evaluate/check-expression.cpp +++ b/flang/lib/Evaluate/check-expression.cpp @@ -678,8 +678,15 @@ if (!(*this)(symbol).has_value()) { return false; } else if (auto rank{CheckSubscripts(x.subscript())}) { - // a(:)%b(1,1) is not contiguous; a(1)%b(:,:) is - return *rank > 0 || x.Rank() == 0; + if (x.Rank() == 0) { + return true; + } else if (*rank > 0) { + // a(1)%b(:,:) is contiguous if an only if a(1)%b is contiguous. + return (*this)(x.base()); + } else { + // a(:)%b(1,1) is not contiguous. + return false; + } } else { return false; } diff --git a/flang/test/Semantics/assign03.f90 b/flang/test/Semantics/assign03.f90 --- a/flang/test/Semantics/assign03.f90 +++ b/flang/test/Semantics/assign03.f90 @@ -277,6 +277,8 @@ logical, parameter :: l4 = is_contiguous(x%a(:,v)) !ERROR: Must be a constant value logical, parameter :: l5 = is_contiguous(y(v,1)%a(1,1)) + !ERROR: Must be a constant value + logical, parameter :: l6 = is_contiguous(p(:)) end subroutine test3(b) integer, intent(inout) :: b(..)