// expressions, so it's safe to defer processing their definitions.)
void ResolveNamesVisitor::AnalyzeStmtFunctionStmt(
const parser::StmtFunctionStmt &stmtFunc) {
- Symbol *symbol{std::get<parser::Name>(stmtFunc.t).symbol};
+ const auto &name{std::get<parser::Name>(stmtFunc.t)};
+ Symbol *symbol{name.symbol};
auto *details{symbol ? symbol->detailsIf<SubprogramDetails>() : nullptr};
if (!details || !symbol->scope()) {
return;
PopScope();
if (auto expr{AnalyzeExpr(context(), stmtFunc)}) {
if (auto type{evaluate::DynamicType::From(*symbol)}) {
- if (auto converted{ConvertToType(*type, std::move(*expr))}) {
+ if (auto converted{evaluate::ConvertToType(*type, std::move(*expr))}) {
details->set_stmtFunction(std::move(*converted));
+ } else {
+ Say(name.source,
+ "Defining expression of statement function '%s' cannot be converted to its result type %s"_err_en_US,
+ name.source, type->AsFortran());
}
} else {
details->set_stmtFunction(std::move(*expr));
!PORTABILITY: Statement function 'sf8' should not pass an array argument that is not a whole array
sf8(n) = sum(a(1:2))
sf8a(n) = sum(a) ! ok
+ integer :: sf9
+ !ERROR: Defining expression of statement function 'sf9' cannot be converted to its result type INTEGER(4)
+ sf9(n) = "bad"
contains
real function explicit(x,y)
integer, intent(in) :: x