From 7ede0b2cc520da59e8459563cbd1a36cc8492f86 Mon Sep 17 00:00:00 2001 From: Peter Klausler Date: Fri, 14 Oct 2022 14:28:22 -0700 Subject: [PATCH] [flang] Complex constructors are scalar only The common language extension that allows arbitary expressions to be used as components in a complex constructor (x,y) -- not both constant, since that would make it a complex literal constant -- still have to be scalar; it's not an elemental operation like the CMPLX() intrinsic function is. Differential Revision: https://reviews.llvm.org/D136978 --- flang/lib/Semantics/expression.cpp | 8 ++++++++ flang/test/Semantics/expr-errors05.f90 | 7 +++++++ 2 files changed, 15 insertions(+) create mode 100644 flang/test/Semantics/expr-errors05.f90 diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp index 47421ef..2fad785 100644 --- a/flang/lib/Semantics/expression.cpp +++ b/flang/lib/Semantics/expression.cpp @@ -2851,6 +2851,14 @@ MaybeExpr ExpressionAnalyzer::Analyze( const parser::Expr::ComplexConstructor &x) { auto re{Analyze(std::get<0>(x.t).value())}; auto im{Analyze(std::get<1>(x.t).value())}; + if (re && re->Rank() > 0) { + context().Say(std::get<0>(x.t).value().source, + "Real part of complex constructor must be scalar"_err_en_US); + } + if (im && im->Rank() > 0) { + context().Say(std::get<1>(x.t).value().source, + "Imaginary part of complex constructor must be scalar"_err_en_US); + } if (re && im) { ConformabilityCheck(GetContextualMessages(), *re, *im); } diff --git a/flang/test/Semantics/expr-errors05.f90 b/flang/test/Semantics/expr-errors05.f90 new file mode 100644 index 0000000..1f1a7c5 --- /dev/null +++ b/flang/test/Semantics/expr-errors05.f90 @@ -0,0 +1,7 @@ +! RUN: %python %S/test_errors.py %s %flang_fc1 +! The components of a complex constructor (extension) must be scalar +!ERROR: Real part of complex constructor must be scalar +complex, parameter :: z1(*) = ([1.,2.], 3.) +!ERROR: Imaginary part of complex constructor must be scalar +complex, parameter :: z2(*) = (4., [5.,6.]) +end -- 2.7.4