using T = Type<TypeCategory::Integer, KIND>;
ActualArguments &args{funcRef.arguments()};
if (const auto *array{UnwrapExpr<Expr<SomeType>>(args[0])}) {
- if (int rank{array->Rank()}; rank > 0) {
+ if (int rank{array->Rank()}; rank > 0 && !IsAssumedRank(*array)) {
std::optional<int> dim;
if (funcRef.Rank() == 0) {
// Optional DIM= argument is present: result is scalar.
if (auto dim64{ToInt64(args[1])}) {
if (*dim64 < 1 || *dim64 > rank) {
- context.messages().Say("DIM=%jd dimension is out of range for "
- "rank-%d array"_err_en_US,
+ context.messages().Say(
+ "DIM=%jd dimension is out of range for rank-%d array"_err_en_US,
*dim64, rank);
return MakeInvalidIntrinsic<T>(std::move(funcRef));
} else {
using T = Type<TypeCategory::Integer, KIND>;
ActualArguments &args{funcRef.arguments()};
if (auto *array{UnwrapExpr<Expr<SomeType>>(args[0])}) {
- if (int rank{array->Rank()}; rank > 0) {
+ if (int rank{array->Rank()}; rank > 0 && !IsAssumedRank(*array)) {
std::optional<int> dim;
if (funcRef.Rank() == 0) {
// Optional DIM= argument is present: result is scalar.
if (auto dim64{ToInt64(args[1])}) {
if (*dim64 < 1 || *dim64 > rank) {
- context.messages().Say("DIM=%jd dimension is out of range for "
- "rank-%d array"_err_en_US,
+ context.messages().Say(
+ "DIM=%jd dimension is out of range for rank-%d array"_err_en_US,
*dim64, rank);
return MakeInvalidIntrinsic<T>(std::move(funcRef));
} else {
takeBoundsFromShape = false;
if (dim) {
if (semantics::IsAssumedSizeArray(symbol) && *dim == rank - 1) {
- context.messages().Say("DIM=%jd dimension is out of range for "
- "rank-%d assumed-size array"_err_en_US,
+ context.messages().Say(
+ "DIM=%jd dimension is out of range for rank-%d assumed-size array"_err_en_US,
rank, rank);
return MakeInvalidIntrinsic<T>(std::move(funcRef));
} else if (auto ub{GetUBOUND(context, *named, *dim)}) {
program test_size
real :: scalar
real, dimension(5, 5) :: array
- call test(array)
+ call test(array, array)
contains
- subroutine test(arg)
+ subroutine test(arg, assumedRank)
real, dimension(5, *) :: arg
+ real, dimension(..) :: assumedRank
!ERROR: A dim= argument is required for 'size' when the array is assumed-size
print *, size(arg)
!ERROR: missing mandatory 'dim=' argument
print *, size(scalar)
!ERROR: missing mandatory 'dim=' argument
print *, ubound(scalar)
+ select rank(assumedRank)
+ rank(1)
+ !ERROR: DIM=2 dimension is out of range for rank-1 array
+ print *, lbound(assumedRank, dim=2)
+ !ERROR: DIM=2 dimension is out of range for rank-1 array
+ print *, ubound(assumedRank, dim=2)
+ end select
! But these cases are fine:
print *, size(arg, dim=1)
print *, ubound(arg, dim=1)
print *, ubound(arg(:,1))
print *, shape(scalar)
print *, shape(arg(:,1))
+ print *, lbound(assumedRank, dim=2) ! can't check until run time
+ print *, ubound(assumedRank, dim=2)
+ select rank(assumedRank)
+ rank(3)
+ print *, lbound(assumedRank, dim=2)
+ print *, ubound(assumedRank, dim=2)
+ rank default
+ print *, lbound(assumedRank, dim=2)
+ print *, ubound(assumedRank, dim=2)
+ end select
end subroutine
end