Skip to content

Commit

Permalink
[flang] Accept whole assumed-size arrays as variable selectors
Browse files Browse the repository at this point in the history
Include variable selectors ("select type (x => y)") as a context
in which a whole assumed-size array may legitimately appear.

Fixes #81910.
  • Loading branch information
klausler committed Feb 28, 2024
1 parent 822142f commit 43498f2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 8 additions & 3 deletions flang/lib/Semantics/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,8 @@ MaybeExpr ExpressionAnalyzer::Analyze(const parser::Name &n) {
}
}
if (!isWholeAssumedSizeArrayOk_ &&
semantics::IsAssumedSizeArray(*n.symbol)) { // C1002, C1014, C1231
semantics::IsAssumedSizeArray(
ResolveAssociations(*n.symbol))) { // C1002, C1014, C1231
AttachDeclaration(
SayAt(n,
"Whole assumed-size array '%s' may not appear here without subscripts"_err_en_US,
Expand Down Expand Up @@ -3741,9 +3742,12 @@ MaybeExpr ExpressionAnalyzer::Analyze(const parser::Selector &selector) {
}
}
}
// Not a Variable -> FunctionReference
auto restorer{AllowWholeAssumedSizeArray()};
return Analyze(selector.u);
} else { // Expr
return Analyze(selector.u);
}
// Not a Variable -> FunctionReference; handle normally as Variable or Expr
return Analyze(selector.u);
}

MaybeExpr ExpressionAnalyzer::Analyze(const parser::DataStmtConstant &x) {
Expand Down Expand Up @@ -3999,6 +4003,7 @@ void ArgumentAnalyzer::Analyze(
const parser::ActualArgSpec &arg, bool isSubroutine) {
// TODO: C1534: Don't allow a "restricted" specific intrinsic to be passed.
std::optional<ActualArgument> actual;
auto restorer{context_.AllowWholeAssumedSizeArray()};
common::visit(
common::visitors{
[&](const common::Indirection<parser::Expr> &x) {
Expand Down
7 changes: 7 additions & 0 deletions flang/test/Semantics/assign04.f90
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ subroutine s6(x)
x(:) = [1, 2, 3]
!ERROR: Whole assumed-size array 'x' may not appear here without subscripts
x = [1, 2, 3]
associate (y => x) ! ok
!ERROR: Whole assumed-size array 'y' may not appear here without subscripts
y = [1, 2, 3]
end associate
!ERROR: Whole assumed-size array 'x' may not appear here without subscripts
associate (y => (x))
end associate
end

module m7
Expand Down

0 comments on commit 43498f2

Please sign in to comment.