Puzzle for Friday

Puzzle for Friday

I have an abstract derived type I use as a base for some concrete types. The abstract type some data that is common for all the concrete types and some deferred bindings I want to ensure get implemented by all the children. This all seams like a good use for OO Fortran.

But here is the catch:

I want to finalize the data in the abstract type. So I place a FINAL declaration in the abstract type with a dummy argument that is non-polymorphic according to the rules for a FINAL routine. But it produces a compiler error because it is illegal to declare a non-polymorphic argument of an abstract data type. Is this a compiler error or an oversight in the standard?

2 帖子 / 0 全新

It is not a compiler error - you cannot conceptually have a non-polymorphic abstract thing - hence C406 in F2008.  I can see reasons for why it wouldn't be considered an oversight - by the time the finalizer is being called for a parent type the bits (and behaviour) of the object that correspond to the extension have gone - so why make the finalizer argument polymorphic?

The solution is to place the data components in a non-abstract grandparent type (which has the finalizer) which the abstract type then extends.