Symbol *DeclarationVisitor::DeclareStatementEntity(const parser::Name &name,
const std::optional<parser::IntegerTypeSpec> &type) {
+ const DeclTypeSpec *declTypeSpec{nullptr};
if (auto *prev{FindSymbol(name)}) {
if (prev->owner() == currScope()) {
SayAlreadyDeclared(name, *prev);
return nullptr;
}
name.symbol = nullptr;
+ declTypeSpec = prev->GetType();
}
Symbol &symbol{DeclareEntity<ObjectEntityDetails>(name, {})};
- if (symbol.has<ObjectEntityDetails>()) {
- const DeclTypeSpec *declTypeSpec{nullptr};
- if (type.has_value()) {
- BeginDeclTypeSpec();
- DeclarationVisitor::Post(*type);
- declTypeSpec = GetDeclTypeSpec();
- EndDeclTypeSpec();
- }
- if (declTypeSpec != nullptr) {
- SetType(name, *declTypeSpec);
- } else {
- ApplyImplicitRules(symbol);
- }
- CheckScalarIntegerType(name);
- return Resolve(name, &symbol);
+ if (!symbol.has<ObjectEntityDetails>()) {
+ return nullptr; // error was reported in DeclareEntity
}
- return nullptr;
+ if (type.has_value()) {
+ BeginDeclTypeSpec();
+ DeclarationVisitor::Post(*type);
+ declTypeSpec = GetDeclTypeSpec();
+ EndDeclTypeSpec();
+ }
+ if (declTypeSpec != nullptr) {
+ SetType(name, *declTypeSpec);
+ } else {
+ ApplyImplicitRules(symbol);
+ }
+ CheckScalarIntegerType(name);
+ return Resolve(name, &symbol);
}
// Set the type of an entity or report an error.
y = 1
end block
end
+
+subroutine s3
+ implicit none
+ integer :: i, j
+ block
+ import, none
+ !ERROR: No explicit type declared for 'i'
+ real :: a(16) = [(i, i=1, 16)]
+ !ERROR: No explicit type declared for 'j'
+ data(a(j), j=1, 16) / 16 * 0.0 /
+ end block
+end
+
+subroutine s4
+ real :: i, j
+ !ERROR: Variable 'i' is not integer
+ real :: a(16) = [(i, i=1, 16)]
+ !ERROR: Variable 'j' is not integer
+ data(a(j), j=1, 16) / 16 * 0.0 /
+end
!DEF: /s3 Subprogram
subroutine s3
+ !DEF: /s3/j ObjectEntity INTEGER(8)
+ integer(kind=8) j
block
!DEF: /s3/Block1/t DerivedType
type :: t
!DEF: /s3/Block1/t/x ObjectEntity REAL(4)
!DEF: /s3/Block1/t/ImpliedDos1/i (implicit) ObjectEntity INTEGER(4)
real :: x(10) = [(i, i=1,10)]
+ !DEF: /s3/Block1/t/y ObjectEntity REAL(4)
+ !DEF: /s3/Block1/t/ImpliedDos2/j ObjectEntity INTEGER(8)
+ real :: y(10) = [(j, j=1,10)]
end type
end block
end subroutine