}
static bool NeedsType(const Symbol &symbol) {
- if (symbol.GetType()) {
- return false;
- }
- if (auto *details{symbol.detailsIf<ProcEntityDetails>()}) {
- if (details->interface().symbol()) {
- return false; // the interface determines the type
- }
- if (!symbol.test(Symbol::Flag::Function)) {
- return false; // not known to be a function
- }
- }
- return true;
+ return symbol.GetType() == nullptr &&
+ std::visit(
+ common::visitors{
+ [](const EntityDetails &) { return true; },
+ [](const ObjectEntityDetails &) { return true; },
+ [](const AssocEntityDetails &) { return true; },
+ [](const auto &) { return false; },
+ },
+ symbol.details());
}
void ScopeHandler::ApplyImplicitRules(Symbol &symbol) {
if (NeedsType(symbol)) {
ResolveSpecificationParts(child);
}
ExecutionPartSkimmer{scope}.Walk(node.exec());
- // Convert function results and dummy arguments to objects if we don't
- // already known by now that they're procedures.
- if (currScope().kind() == Scope::Kind::Subprogram) {
- for (const auto &pair : currScope()) {
- Symbol &symbol{*pair.second};
- if (auto *details{symbol.detailsIf<EntityDetails>()}) {
- if (details->isFuncResult() || details->isDummy()) {
- ConvertToObjectEntity(symbol);
- }
- }
- }
+ PopScope();
+ // Ensure every object entity has a type:
+ for (auto &pair : *node.scope()) {
+ ApplyImplicitRules(*pair.second);
}
- // Subtlety: PopScope() is not called here because we want to defer
- // conversions of other uncategorized entities into objects until after
- // we have traversed the executable part of the subprogram.
- SetScope(currScope().parent());
}
// Add SubprogramNameDetails symbols for contained subprograms
--- /dev/null
+! Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
+!
+! Licensed under the Apache License, Version 2.0 (the "License");
+! you may not use this file except in compliance with the License.
+! You may obtain a copy of the License at
+!
+! http://www.apache.org/licenses/LICENSE-2.0
+!
+! Unless required by applicable law or agreed to in writing, software
+! distributed under the License is distributed on an "AS IS" BASIS,
+! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+! See the License for the specific language governing permissions and
+! limitations under the License.
+
+! Check that implicitly typed entities get a type in the module file.
+
+module m
+ public :: a
+ private :: b
+ protected :: i
+ allocatable :: j
+end
+
+!Expect: m.mod
+!module m
+! real(4)::a
+! real(4),private::b
+! integer(4),protected::i
+! integer(4),allocatable::j
+!end