forked from OSchip/llvm-project
[flang] Improve message for assignment to subprogram
In the example below we were producing the error message "Assignment to constant 'f' is not allowed": ``` function f() result(r) f = 1.0 end ``` This changes it to a more helpful message when the LHS is a subprogram name and also mentions the function result name when it's a function. Differential Revision: https://reviews.llvm.org/D85483
This commit is contained in:
parent
f13f2e16f0
commit
d8713523a2
|
@ -2704,10 +2704,22 @@ void ArgumentAnalyzer::Analyze(const parser::Variable &x) {
|
|||
actuals_.emplace_back(std::move(*expr));
|
||||
return;
|
||||
}
|
||||
const Symbol *symbol{GetFirstSymbol(*expr)};
|
||||
context_.Say(x.GetSource(),
|
||||
"Assignment to constant '%s' is not allowed"_err_en_US,
|
||||
symbol ? symbol->name() : x.GetSource());
|
||||
const Symbol *symbol{GetLastSymbol(*expr)};
|
||||
if (!symbol) {
|
||||
context_.SayAt(x, "Assignment to constant '%s' is not allowed"_err_en_US,
|
||||
x.GetSource());
|
||||
} else if (auto *subp{symbol->detailsIf<semantics::SubprogramDetails>()}) {
|
||||
auto *msg{context_.SayAt(x,
|
||||
"Assignment to subprogram '%s' is not allowed"_err_en_US,
|
||||
symbol->name())};
|
||||
if (subp->isFunction()) {
|
||||
const auto &result{subp->result().name()};
|
||||
msg->Attach(result, "Function result is '%s'"_err_en_US, result);
|
||||
}
|
||||
} else {
|
||||
context_.SayAt(x, "Assignment to constant '%s' is not allowed"_err_en_US,
|
||||
symbol->name());
|
||||
}
|
||||
}
|
||||
fatalErrors_ = true;
|
||||
}
|
||||
|
|
|
@ -115,3 +115,13 @@ subroutine s7
|
|||
integer :: a(10), v(10)
|
||||
a(v(:)) = 1 ! vector subscript is ok
|
||||
end
|
||||
|
||||
subroutine s8
|
||||
!ERROR: Assignment to subprogram 's8' is not allowed
|
||||
s8 = 1.0
|
||||
end
|
||||
|
||||
real function f9() result(r)
|
||||
!ERROR: Assignment to subprogram 'f9' is not allowed
|
||||
f9 = 1.0
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue