@@ -193,6 +193,15 @@ static std::optional<parser::Message> WhyNotDefinableLast(parser::CharBlock at,
193193 return WhyNotDefinableLast (at, scope, flags, dataRef->GetLastSymbol ());
194194 }
195195 }
196+ auto dyType{evaluate::DynamicType::From (ultimate)};
197+ const auto *inPure{FindPureProcedureContaining (scope)};
198+ if (inPure && !flags.test (DefinabilityFlag::PolymorphicOkInPure) &&
199+ flags.test (DefinabilityFlag::PotentialDeallocation) && dyType &&
200+ dyType->IsPolymorphic ()) {
201+ return BlameSymbol (at,
202+ " '%s' is a whole polymorphic object in a pure subprogram" _en_US,
203+ original);
204+ }
196205 if (flags.test (DefinabilityFlag::PointerDefinition)) {
197206 if (flags.test (DefinabilityFlag::AcceptAllocatable)) {
198207 if (!IsAllocatableOrObjectPointer (&ultimate)) {
@@ -210,26 +219,17 @@ static std::optional<parser::Message> WhyNotDefinableLast(parser::CharBlock at,
210219 " '%s' is an entity with either an EVENT_TYPE or LOCK_TYPE" _en_US,
211220 original);
212221 }
213- if (FindPureProcedureContaining (scope)) {
214- if (auto dyType{evaluate::DynamicType::From (ultimate)}) {
215- if (!flags.test (DefinabilityFlag::PolymorphicOkInPure)) {
216- if (dyType->IsPolymorphic ()) { // C1596
217- return BlameSymbol (
218- at, " '%s' is polymorphic in a pure subprogram" _en_US, original);
219- }
220- }
221- if (const Symbol * impure{HasImpureFinal (ultimate)}) {
222- return BlameSymbol (at, " '%s' has an impure FINAL procedure '%s'" _en_US,
223- original, impure->name ());
224- }
222+ if (dyType && inPure) {
223+ if (const Symbol * impure{HasImpureFinal (ultimate)}) {
224+ return BlameSymbol (at, " '%s' has an impure FINAL procedure '%s'" _en_US,
225+ original, impure->name ());
226+ }
227+ if (!flags.test (DefinabilityFlag::PolymorphicOkInPure)) {
225228 if (const DerivedTypeSpec * derived{GetDerivedTypeSpec (dyType)}) {
226- if (!flags.test (DefinabilityFlag::PolymorphicOkInPure)) {
227- if (auto bad{
228- FindPolymorphicAllocatablePotentialComponent (*derived)}) {
229- return BlameSymbol (at,
230- " '%s' has polymorphic component '%s' in a pure subprogram" _en_US,
231- original, bad.BuildResultDesignatorName ());
232- }
229+ if (auto bad{FindPolymorphicAllocatablePotentialComponent (*derived)}) {
230+ return BlameSymbol (at,
231+ " '%s' has polymorphic component '%s' in a pure subprogram" _en_US,
232+ original, bad.BuildResultDesignatorName ());
233233 }
234234 }
235235 }
@@ -243,7 +243,7 @@ static std::optional<parser::Message> WhyNotDefinable(parser::CharBlock at,
243243 const evaluate::DataRef &dataRef) {
244244 auto whyNotBase{
245245 WhyNotDefinableBase (at, scope, flags, dataRef.GetFirstSymbol (),
246- std::holds_alternative< evaluate::SymbolRef> (dataRef. u ) ,
246+ evaluate::UnwrapWholeSymbolDataRef (dataRef) != nullptr ,
247247 DefinesComponentPointerTarget (dataRef, flags))};
248248 if (!whyNotBase || !whyNotBase->IsFatal ()) {
249249 if (auto whyNotLast{
0 commit comments