Perl-Apollo / Corinna

Corinna - Bring Modern OO to the Core of Perl
Artistic License 2.0
156 stars 19 forks source link

Deterministic Destruction is incorrect #57

Closed haarg closed 2 years ago

haarg commented 2 years ago

9.2.1 Deterministic Destruction states:

In Corinna, fields are indended to be destroyed in reverse order of declaration, instance fields and then class (common) fields, from parent to child. Consider the following (note that the syntax for :common might change):

class Parent {
    field $one;
    field $two;
    field $three :common;
}

class Child :isa(Parent) {
    field $four;
    field $five :common;
    field $six;
}

The destruction order should be guaranteed to be:

  1. $six
  2. $four
  3. $five # class data
  4. $two
  5. $one
  6. $three # class data

This does not make sense. Destruction of class data should not be mixed with destruction of object data. It should always happen last. Consider that normal object destruction would not destroy class data at all - it would only be destroyed during global destruction.

Ovid commented 2 years ago

Sorry, didn't see this comment earlier.

Yes, you're absolutely correct. I wasn't thinking.

In the future, this might apply if classes become "first class" and the class itself can fall out of scope, but clearly that cannot apply now.

Ovid commented 2 years ago

Addressed in 9.2.1.

Important: at the current time, class data will only be destroyed in global destruction. In the future, if Corinna classes can become "first class" in the Perl language, if a class can fall out of scope prior to global destruction, then yes, class data can be destroyed prior to global construction (e.g, for an anonymous class created a runtime).