Skip to content

Commit ddb3553

Browse files
committed
[flang] Add missing source location to a semantic error message
Ensure that the semantic error "An allocatable or pointer component reference must be applied to a scalar base" is emitted with a source code location. Differential Revision: https://reviews.llvm.org/D135215
1 parent aa065c0 commit ddb3553

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

flang/lib/Semantics/expression.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,7 @@ MaybeExpr ExpressionAnalyzer::Analyze(const parser::StructureComponent &sc) {
11451145
return std::nullopt;
11461146
} else if (std::optional<DataRef> dataRef{
11471147
ExtractDataRef(std::move(*dtExpr))}) {
1148+
auto restorer{GetContextualMessages().SetLocation(name)};
11481149
if (auto component{
11491150
CreateComponent(std::move(*dataRef), *sym, *dtSpec->scope())}) {
11501151
return Designate(DataRef{std::move(*component)});

flang/test/Semantics/expr-errors04.f90

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ subroutine real_generic()
1414
complex :: c, c2(2)
1515
integer :: x, x2(2)
1616
character(10) :: s, s2(2)
17+
real, pointer :: p
18+
real, allocatable :: a
1719
contains
1820
procedure, nopass :: info1 => real_info1
1921
procedure, nopass :: info2 => real_info2
@@ -108,4 +110,17 @@ subroutine real_generic()
108110
!ERROR: Reference to rank-2 object 't1' has 1 subscripts
109111
call t%t3%t2%t1(1:)%g1
110112

113+
!ERROR: An allocatable or pointer component reference must be applied to a scalar base
114+
print *, t(1)%t3(1)%t2(1)%t1%p
115+
!ERROR: An allocatable or pointer component reference must be applied to a scalar base
116+
print *, t%t3(1)%t2(1)%t1(1,1)%p
117+
!ERROR: An allocatable or pointer component reference must be applied to a scalar base
118+
print *, t(1)%t3(1)%t2(1)%t1%a
119+
!ERROR: An allocatable or pointer component reference must be applied to a scalar base
120+
print *, t%t3(1)%t2(1)%t1(1,1)%a
121+
!ERROR: An allocatable or pointer component reference must be applied to a scalar base
122+
t(1)%t3(1)%t2(1)%t1%p => null()
123+
!ERROR: An allocatable or pointer component reference must be applied to a scalar base
124+
t%t3(1)%t2(1)%t1(1,1)%p => null()
125+
111126
end

0 commit comments

Comments
 (0)