@@ -115,14 +115,14 @@ Expr<Type<TypeCategory::Integer, KIND>> LBOUND(FoldingContext &context,
115
115
using T = Type<TypeCategory::Integer, KIND>;
116
116
ActualArguments &args{funcRef.arguments ()};
117
117
if (const auto *array{UnwrapExpr<Expr<SomeType>>(args[0 ])}) {
118
- if (int rank{array->Rank ()}; rank > 0 ) {
118
+ if (int rank{array->Rank ()}; rank > 0 && ! IsAssumedRank (*array) ) {
119
119
std::optional<int > dim;
120
120
if (funcRef.Rank () == 0 ) {
121
121
// Optional DIM= argument is present: result is scalar.
122
122
if (auto dim64{ToInt64 (args[1 ])}) {
123
123
if (*dim64 < 1 || *dim64 > rank) {
124
- context.messages ().Say (" DIM=%jd dimension is out of range for "
125
- " rank-%d array" _err_en_US,
124
+ context.messages ().Say (
125
+ " DIM=%jd dimension is out of range for rank-%d array" _err_en_US,
126
126
*dim64, rank);
127
127
return MakeInvalidIntrinsic<T>(std::move (funcRef));
128
128
} else {
@@ -169,14 +169,14 @@ Expr<Type<TypeCategory::Integer, KIND>> UBOUND(FoldingContext &context,
169
169
using T = Type<TypeCategory::Integer, KIND>;
170
170
ActualArguments &args{funcRef.arguments ()};
171
171
if (auto *array{UnwrapExpr<Expr<SomeType>>(args[0 ])}) {
172
- if (int rank{array->Rank ()}; rank > 0 ) {
172
+ if (int rank{array->Rank ()}; rank > 0 && ! IsAssumedRank (*array) ) {
173
173
std::optional<int > dim;
174
174
if (funcRef.Rank () == 0 ) {
175
175
// Optional DIM= argument is present: result is scalar.
176
176
if (auto dim64{ToInt64 (args[1 ])}) {
177
177
if (*dim64 < 1 || *dim64 > rank) {
178
- context.messages ().Say (" DIM=%jd dimension is out of range for "
179
- " rank-%d array" _err_en_US,
178
+ context.messages ().Say (
179
+ " DIM=%jd dimension is out of range for rank-%d array" _err_en_US,
180
180
*dim64, rank);
181
181
return MakeInvalidIntrinsic<T>(std::move (funcRef));
182
182
} else {
@@ -194,8 +194,8 @@ Expr<Type<TypeCategory::Integer, KIND>> UBOUND(FoldingContext &context,
194
194
takeBoundsFromShape = false ;
195
195
if (dim) {
196
196
if (semantics::IsAssumedSizeArray (symbol) && *dim == rank - 1 ) {
197
- context.messages ().Say (" DIM=%jd dimension is out of range for "
198
- " rank-%d assumed-size array" _err_en_US,
197
+ context.messages ().Say (
198
+ " DIM=%jd dimension is out of range for rank-%d assumed-size array" _err_en_US,
199
199
rank, rank);
200
200
return MakeInvalidIntrinsic<T>(std::move (funcRef));
201
201
} else if (auto ub{GetUBOUND (context, *named, *dim)}) {
0 commit comments