Skip to content

Commit 3b1164a

Browse files
committed
[flang] Accept whole assumed-size arrays as variable selectors
Include variable selectors ("select type (x => y)") as a context in which a whole assumed-size array may legitimately appear. Fixes #81910.
1 parent 822142f commit 3b1164a

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

flang/lib/Evaluate/tools.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,8 +1400,10 @@ static const Symbol *GetAssociatedVariable(const AssocEntityDetails &details) {
14001400
const Symbol &GetAssociationRoot(const Symbol &original) {
14011401
const Symbol &symbol{ResolveAssociations(original)};
14021402
if (const auto *details{symbol.detailsIf<AssocEntityDetails>()}) {
1403-
if (const Symbol * root{GetAssociatedVariable(*details)}) {
1404-
return *root;
1403+
if (!details->rank()) {
1404+
if (const Symbol * root{GetAssociatedVariable(*details)}) {
1405+
return *root;
1406+
}
14051407
}
14061408
}
14071409
return symbol;

flang/lib/Semantics/expression.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,8 @@ MaybeExpr ExpressionAnalyzer::Analyze(const parser::Name &n) {
973973
}
974974
}
975975
if (!isWholeAssumedSizeArrayOk_ &&
976-
semantics::IsAssumedSizeArray(*n.symbol)) { // C1002, C1014, C1231
976+
semantics::IsAssumedSizeArray(
977+
GetAssociationRoot(*n.symbol))) { // C1002, C1014, C1231
977978
AttachDeclaration(
978979
SayAt(n,
979980
"Whole assumed-size array '%s' may not appear here without subscripts"_err_en_US,
@@ -3741,9 +3742,12 @@ MaybeExpr ExpressionAnalyzer::Analyze(const parser::Selector &selector) {
37413742
}
37423743
}
37433744
}
3745+
// Not a Variable -> FunctionReference
3746+
auto restorer{AllowWholeAssumedSizeArray()};
3747+
return Analyze(selector.u);
3748+
} else { // Expr
3749+
return Analyze(selector.u);
37443750
}
3745-
// Not a Variable -> FunctionReference; handle normally as Variable or Expr
3746-
return Analyze(selector.u);
37473751
}
37483752

37493753
MaybeExpr ExpressionAnalyzer::Analyze(const parser::DataStmtConstant &x) {
@@ -3999,6 +4003,7 @@ void ArgumentAnalyzer::Analyze(
39994003
const parser::ActualArgSpec &arg, bool isSubroutine) {
40004004
// TODO: C1534: Don't allow a "restricted" specific intrinsic to be passed.
40014005
std::optional<ActualArgument> actual;
4006+
auto restorer{context_.AllowWholeAssumedSizeArray()};
40024007
common::visit(
40034008
common::visitors{
40044009
[&](const common::Indirection<parser::Expr> &x) {

flang/test/Semantics/assign04.f90

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ subroutine s6(x)
105105
x(:) = [1, 2, 3]
106106
!ERROR: Whole assumed-size array 'x' may not appear here without subscripts
107107
x = [1, 2, 3]
108+
associate (y => x) ! ok
109+
!ERROR: Whole assumed-size array 'y' may not appear here without subscripts
110+
y = [1, 2, 3]
111+
end associate
112+
!ERROR: Whole assumed-size array 'x' may not appear here without subscripts
113+
associate (y => (x))
114+
end associate
108115
end
109116

110117
module m7

0 commit comments

Comments
 (0)