[flang] Check for errors when analyzing array constructors (#173092)
Errors in array constructor values result in the array having less elements than it should, which can cause other errors that will confuse the user. Avoid this by not returning an expression on errors. Fixes #127425
This commit is contained in:
parent
9e78d8a4fb
commit
fa53d9285a
2 changed files with 14 additions and 0 deletions
|
|
@ -2075,11 +2075,15 @@ MaybeExpr ArrayConstructorContext::ToExpr() {
|
|||
|
||||
MaybeExpr ExpressionAnalyzer::Analyze(const parser::ArrayConstructor &array) {
|
||||
const parser::AcSpec &acSpec{array.v};
|
||||
bool hadAnyFatalError{context_.AnyFatalError()};
|
||||
ArrayConstructorContext acContext{
|
||||
*this, AnalyzeTypeSpec(acSpec.type, GetFoldingContext())};
|
||||
for (const parser::AcValue &value : acSpec.values) {
|
||||
acContext.Add(value);
|
||||
}
|
||||
if (!hadAnyFatalError && context_.AnyFatalError()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return acContext.ToExpr();
|
||||
}
|
||||
|
||||
|
|
|
|||
10
flang/test/Semantics/bug127425.f90
Normal file
10
flang/test/Semantics/bug127425.f90
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
! RUN: %python %S/test_errors.py %s %flang_fc1
|
||||
|
||||
program main
|
||||
implicit none
|
||||
integer :: ja, jb, j3, j4, j5
|
||||
pointer (j1,ja)
|
||||
pointer (j2,jb)
|
||||
!ERROR: Values in array constructor must have the same declared type when no explicit type appears
|
||||
if (any((/j1,j2,j3,j4,j5/)/=(/1,2,3,4,5/))) print *,'fail'
|
||||
end program main
|
||||
Loading…
Reference in a new issue