@@ -4554,6 +4554,9 @@ bool DeclarationVisitor::Pre(const parser::NamedConstantDef &x) {
4554
4554
}
4555
4555
const auto &expr{std::get<parser::ConstantExpr>(x.t )};
4556
4556
auto &details{symbol.get <ObjectEntityDetails>()};
4557
+ if (details.init () || symbol.test (Symbol::Flag::InDataStmt)) {
4558
+ Say (name, " Named constant '%s' already has a value" _err_en_US);
4559
+ }
4557
4560
if (inOldStyleParameterStmt_) {
4558
4561
// non-standard extension PARAMETER statement (no parentheses)
4559
4562
Walk (expr);
@@ -4932,6 +4935,8 @@ Symbol &DeclarationVisitor::DeclareObjectEntity(
4932
4935
} else if (MustBeScalar (symbol)) {
4933
4936
Say (name,
4934
4937
" '%s' appeared earlier as a scalar actual argument to a specification function" _warn_en_US);
4938
+ } else if (details->init () || symbol.test (Symbol::Flag::InDataStmt)) {
4939
+ Say (name, " '%s' was initialized earlier as a scalar" _err_en_US);
4935
4940
} else {
4936
4941
details->set_shape (arraySpec ());
4937
4942
}
@@ -7577,9 +7582,11 @@ void DeclarationVisitor::Initialization(const parser::Name &name,
7577
7582
" Pointer initializer must be intrinsic NULL()" _err_en_US);
7578
7583
} else if (IsPointer (ultimate)) {
7579
7584
if (auto *object{ultimate.detailsIf <ObjectEntityDetails>()}) {
7585
+ CHECK (!object->init ());
7580
7586
object->set_init (std::move (*nullInit));
7581
7587
} else if (auto *procPtr{
7582
7588
ultimate.detailsIf <ProcEntityDetails>()}) {
7589
+ CHECK (!procPtr->init ());
7583
7590
procPtr->set_init (nullptr );
7584
7591
}
7585
7592
} else {
@@ -7679,6 +7686,8 @@ void DeclarationVisitor::NonPointerInitialization(
7679
7686
" '%s' is a pointer but is not initialized like one" _err_en_US);
7680
7687
} else if (auto *details{ultimate.detailsIf <ObjectEntityDetails>()}) {
7681
7688
if (details->init ()) {
7689
+ SayWithDecl (name, *name.symbol ,
7690
+ " '%s' has already been initialized" _err_en_US);
7682
7691
} else if (IsAllocatable (ultimate)) {
7683
7692
Say (name, " Allocatable object '%s' cannot be initialized" _err_en_US);
7684
7693
} else if (ultimate.owner ().IsParameterizedDerivedType ()) {
@@ -8928,7 +8937,12 @@ class DeferredCheckVisitor {
8928
8937
resolver_.PointerInitialization (name, *target);
8929
8938
} else if (const auto *expr{
8930
8939
std::get_if<parser::ConstantExpr>(&init->u )}) {
8931
- resolver_.NonPointerInitialization (name, *expr);
8940
+ if (name.symbol ) {
8941
+ if (const auto *object{name.symbol ->detailsIf <ObjectEntityDetails>()};
8942
+ !object || !object->init ()) {
8943
+ resolver_.NonPointerInitialization (name, *expr);
8944
+ }
8945
+ }
8932
8946
}
8933
8947
}
8934
8948
}
0 commit comments