diff --git a/flang/lib/Evaluate/variable.cpp b/flang/lib/Evaluate/variable.cpp --- a/flang/lib/Evaluate/variable.cpp +++ b/flang/lib/Evaluate/variable.cpp @@ -257,8 +257,14 @@ static std::optional> SymbolLEN(const Symbol &sym) { if (auto dyType{DynamicType::From(sym)}) { if (const semantics::ParamValue * len{dyType->charLength()}) { - if (auto intExpr{len->GetExplicit()}) { - return ConvertToType(*std::move(intExpr)); + if (len->isExplicit()) { + if (auto intExpr{len->GetExplicit()}) { + return ConvertToType(*std::move(intExpr)); + } else { + // There was an error constructing this symbol's type. It should + // have a length expression, but we couldn't retrieve it + return std::nullopt; + } } else { return Expr{ DescriptorInquiry{NamedEntity{sym}, DescriptorInquiry::Field::Len}}; diff --git a/flang/test/Semantics/resolve91.f90 b/flang/test/Semantics/resolve91.f90 --- a/flang/test/Semantics/resolve91.f90 +++ b/flang/test/Semantics/resolve91.f90 @@ -44,3 +44,10 @@ real, dimension(:), pointer :: realArray => localArray end type end module m4 + +module m5 + !ERROR: Actual argument for 'string=' has bad type 'REAL(4)' + character(len=len(a)) :: b + !ERROR: The type of 'a' has already been implicitly declared + character(len=len(b)) :: a +end module m5