@@ -955,7 +955,7 @@ class SubprogramVisitor : public virtual ScopeHandler, public InterfaceVisitor {
955
955
bool HandlePreviousCalls (const parser::Name &, Symbol &, Symbol::Flag);
956
956
const Symbol *CheckExtantProc (const parser::Name &, Symbol::Flag);
957
957
// Create a subprogram symbol in the current scope and push a new scope.
958
- Symbol & PushSubprogramScope (const parser::Name &, Symbol::Flag,
958
+ Symbol * PushSubprogramScope (const parser::Name &, Symbol::Flag,
959
959
const parser::LanguageBindingSpec * = nullptr ,
960
960
bool hasModulePrefix = false );
961
961
Symbol *GetSpecificFromGeneric (const parser::Name &);
@@ -4492,10 +4492,13 @@ bool SubprogramVisitor::HandleStmtFunction(const parser::StmtFunctionStmt &x) {
4492
4492
" '%s' has not been declared as an array or pointer-valued function" _err_en_US);
4493
4493
return false ;
4494
4494
}
4495
- auto &symbol{PushSubprogramScope (name, Symbol::Flag::Function)};
4496
- symbol.set (Symbol::Flag::StmtFunction);
4497
- EraseSymbol (symbol); // removes symbol added by PushSubprogramScope
4498
- auto &details{symbol.get <SubprogramDetails>()};
4495
+ Symbol *symbol{PushSubprogramScope (name, Symbol::Flag::Function)};
4496
+ if (!symbol) {
4497
+ return false ;
4498
+ }
4499
+ symbol->set (Symbol::Flag::StmtFunction);
4500
+ EraseSymbol (*symbol); // removes symbol added by PushSubprogramScope
4501
+ auto &details{symbol->get <SubprogramDetails>()};
4499
4502
for (const auto &dummyName : std::get<std::list<parser::Name>>(x.t )) {
4500
4503
ObjectEntityDetails dummyDetails{true };
4501
4504
if (auto *dummySymbol{FindInScope (currScope ().parent (), dummyName)}) {
@@ -5124,19 +5127,22 @@ bool SubprogramVisitor::BeginSubprogram(const parser::Name &name,
5124
5127
}
5125
5128
}
5126
5129
}
5127
- Symbol & newSymbol{
5130
+ Symbol * newSymbol{
5128
5131
PushSubprogramScope (name, subpFlag, bindingSpec, hasModulePrefix)};
5132
+ if (!newSymbol) {
5133
+ return false ;
5134
+ }
5129
5135
if (moduleInterface) {
5130
- newSymbol. get <SubprogramDetails>().set_moduleInterface (*moduleInterface);
5136
+ newSymbol-> get <SubprogramDetails>().set_moduleInterface (*moduleInterface);
5131
5137
if (moduleInterface->attrs ().test (Attr::PRIVATE)) {
5132
- SetImplicitAttr (newSymbol, Attr::PRIVATE);
5138
+ SetImplicitAttr (* newSymbol, Attr::PRIVATE);
5133
5139
} else if (moduleInterface->attrs ().test (Attr::PUBLIC)) {
5134
- SetImplicitAttr (newSymbol, Attr::PUBLIC);
5140
+ SetImplicitAttr (* newSymbol, Attr::PUBLIC);
5135
5141
}
5136
5142
}
5137
5143
if (entryStmts) {
5138
5144
for (const auto &ref : *entryStmts) {
5139
- CreateEntry (*ref, newSymbol);
5145
+ CreateEntry (*ref, * newSymbol);
5140
5146
}
5141
5147
}
5142
5148
return true ;
@@ -5243,12 +5249,16 @@ const Symbol *SubprogramVisitor::CheckExtantProc(
5243
5249
return prev;
5244
5250
}
5245
5251
5246
- Symbol & SubprogramVisitor::PushSubprogramScope (const parser::Name &name,
5252
+ Symbol * SubprogramVisitor::PushSubprogramScope (const parser::Name &name,
5247
5253
Symbol::Flag subpFlag, const parser::LanguageBindingSpec *bindingSpec,
5248
5254
bool hasModulePrefix) {
5249
5255
Symbol *symbol{GetSpecificFromGeneric (name)};
5250
5256
const DeclTypeSpec *previousImplicitType{nullptr };
5251
5257
SourceName previousName;
5258
+ if (symbol && inInterfaceBlock () && !symbol->has <SubprogramDetails>()) {
5259
+ SayAlreadyDeclared (name, *symbol);
5260
+ return nullptr ;
5261
+ }
5252
5262
if (!symbol) {
5253
5263
if (bindingSpec && currScope ().IsGlobal () &&
5254
5264
std::get<std::optional<parser::ScalarDefaultCharConstantExpr>>(
@@ -5277,9 +5287,7 @@ Symbol &SubprogramVisitor::PushSubprogramScope(const parser::Name &name,
5277
5287
if (subpFlag == Symbol::Flag::Function) {
5278
5288
auto &funcResultTop{funcResultStack ().Push (currScope (), name.source )};
5279
5289
funcResultTop.previousImplicitType = previousImplicitType;
5280
- ;
5281
5290
funcResultTop.previousName = previousName;
5282
- ;
5283
5291
}
5284
5292
if (inInterfaceBlock ()) {
5285
5293
auto &details{symbol->get <SubprogramDetails>()};
@@ -5305,7 +5313,7 @@ Symbol &SubprogramVisitor::PushSubprogramScope(const parser::Name &name,
5305
5313
found && found->has <HostAssocDetails>()) {
5306
5314
found->set (subpFlag); // PushScope() created symbol
5307
5315
}
5308
- return * symbol;
5316
+ return symbol;
5309
5317
}
5310
5318
5311
5319
void SubprogramVisitor::PushBlockDataScope (const parser::Name &name) {
0 commit comments