diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp --- a/flang/lib/Semantics/expression.cpp +++ b/flang/lib/Semantics/expression.cpp @@ -871,21 +871,28 @@ std::optional ExpressionAnalyzer::AnalyzeSectionSubscript( const parser::SectionSubscript &ss) { - return std::visit(common::visitors{ - [&](const parser::SubscriptTriplet &t) { - return std::make_optional( - Triplet{TripletPart(std::get<0>(t.t)), - TripletPart(std::get<1>(t.t)), - TripletPart(std::get<2>(t.t))}); - }, - [&](const auto &s) -> std::optional { - if (auto subscriptExpr{AsSubscript(Analyze(s))}) { - return Subscript{std::move(*subscriptExpr)}; - } else { - return std::nullopt; - } - }, - }, + return std::visit( + common::visitors{ + [&](const parser::SubscriptTriplet &t) -> std::optional { + const auto &lower{std::get<0>(t.t)}; + const auto &upper{std::get<1>(t.t)}; + const auto &stride{std::get<2>(t.t)}; + auto result{Triplet{ + TripletPart(lower), TripletPart(upper), TripletPart(stride)}}; + if ((lower && !result.lower()) || (upper && !result.upper())) { + return std::nullopt; + } else { + return std::make_optional(result); + } + }, + [&](const auto &s) -> std::optional { + if (auto subscriptExpr{AsSubscript(Analyze(s))}) { + return Subscript{std::move(*subscriptExpr)}; + } else { + return std::nullopt; + } + }, + }, ss.u); } diff --git a/flang/test/Semantics/assign04.f90 b/flang/test/Semantics/assign04.f90 --- a/flang/test/Semantics/assign04.f90 +++ b/flang/test/Semantics/assign04.f90 @@ -125,3 +125,10 @@ !ERROR: Assignment to subprogram 'f9' is not allowed f9 = 1.0 end + +!ERROR: No explicit type declared for 'n' +subroutine s10(a, n) + implicit none + real a(n) + a(1:n) = 0.0 ! should not get a second error here +end