@@ -89,7 +89,8 @@ static const Symbol &GetRelevantSymbol(const evaluate::DataRef &dataRef,
89
89
90
90
// Check the leftmost (or only) symbol from a data-ref or expression.
91
91
static std::optional<parser::Message> WhyNotDefinableBase (parser::CharBlock at,
92
- const Scope &scope, DefinabilityFlags flags, const Symbol &original) {
92
+ const Scope &scope, DefinabilityFlags flags, const Symbol &original,
93
+ bool isWholeSymbol) {
93
94
const Symbol &ultimate{original.GetUltimate ()};
94
95
bool isPointerDefinition{flags.test (DefinabilityFlag::PointerDefinition)};
95
96
bool acceptAllocatable{flags.test (DefinabilityFlag::AcceptAllocatable)};
@@ -104,15 +105,17 @@ static std::optional<parser::Message> WhyNotDefinableBase(parser::CharBlock at,
104
105
} else if (auto dataRef{evaluate::ExtractDataRef (
105
106
*association->expr (), true , true )}) {
106
107
return WhyNotDefinableBase (at, scope, flags,
107
- GetRelevantSymbol (*dataRef, isPointerDefinition, acceptAllocatable));
108
+ GetRelevantSymbol (*dataRef, isPointerDefinition, acceptAllocatable),
109
+ isWholeSymbol);
108
110
}
109
111
}
110
112
if (isTargetDefinition) {
111
113
} else if (!isPointerDefinition && !IsVariableName (ultimate)) {
112
114
return BlameSymbol (at, " '%s' is not a variable" _en_US, original);
113
115
} else if (IsProtected (ultimate) && IsUseAssociated (original, scope)) {
114
116
return BlameSymbol (at, " '%s' is protected in this scope" _en_US, original);
115
- } else if (IsIntentIn (ultimate)) {
117
+ } else if (IsIntentIn (ultimate) &&
118
+ (!IsPointer (ultimate) || (isWholeSymbol && isPointerDefinition))) {
116
119
return BlameSymbol (
117
120
at, " '%s' is an INTENT(IN) dummy argument" _en_US, original);
118
121
}
@@ -165,6 +168,12 @@ static std::optional<parser::Message> WhyNotDefinableBase(parser::CharBlock at,
165
168
static std::optional<parser::Message> WhyNotDefinableLast (parser::CharBlock at,
166
169
const Scope &scope, DefinabilityFlags flags, const Symbol &original) {
167
170
const Symbol &ultimate{original.GetUltimate ()};
171
+ if (const auto *association{ultimate.detailsIf <AssocEntityDetails>()}) {
172
+ if (auto dataRef{
173
+ evaluate::ExtractDataRef (*association->expr (), true , true )}) {
174
+ return WhyNotDefinableLast (at, scope, flags, dataRef->GetLastSymbol ());
175
+ }
176
+ }
168
177
if (flags.test (DefinabilityFlag::PointerDefinition)) {
169
178
if (flags.test (DefinabilityFlag::AcceptAllocatable)) {
170
179
if (!IsAllocatableOrObjectPointer (&ultimate)) {
@@ -216,7 +225,8 @@ static std::optional<parser::Message> WhyNotDefinable(parser::CharBlock at,
216
225
const Symbol &base{GetRelevantSymbol (dataRef,
217
226
flags.test (DefinabilityFlag::PointerDefinition),
218
227
flags.test (DefinabilityFlag::AcceptAllocatable))};
219
- if (auto whyNot{WhyNotDefinableBase (at, scope, flags, base)}) {
228
+ if (auto whyNot{WhyNotDefinableBase (at, scope, flags, base,
229
+ std::holds_alternative<evaluate::SymbolRef>(dataRef.u ))}) {
220
230
return whyNot;
221
231
} else {
222
232
return WhyNotDefinableLast (at, scope, flags, dataRef.GetLastSymbol ());
@@ -231,12 +241,13 @@ static std::optional<parser::Message> WhyNotDefinable(parser::CharBlock at,
231
241
const Symbol &base{GetRelevantSymbol (dataRef, false , false )};
232
242
DefinabilityFlags baseFlags{flags};
233
243
baseFlags.reset (DefinabilityFlag::PointerDefinition);
234
- return WhyNotDefinableBase (at, scope, baseFlags, base);
244
+ return WhyNotDefinableBase (at, scope, baseFlags, base,
245
+ std::holds_alternative<evaluate::SymbolRef>(dataRef.u ));
235
246
}
236
247
237
248
std::optional<parser::Message> WhyNotDefinable (parser::CharBlock at,
238
249
const Scope &scope, DefinabilityFlags flags, const Symbol &original) {
239
- if (auto base{WhyNotDefinableBase (at, scope, flags, original)}) {
250
+ if (auto base{WhyNotDefinableBase (at, scope, flags, original, true )}) {
240
251
return base;
241
252
}
242
253
return WhyNotDefinableLast (at, scope, flags, original);
0 commit comments