Skip to content

Using nested classes in generic procedures results in serialization override errors #27994

@bradcray

Description

@bradcray

While using a nested class (for reasons of convenience and laziness, not need) without explicit serialize/deserialize methods, I ran into the error:

testit.chpl:9: error: Box.serialize override keyword present but no superclass method matches signature to override
testit.chpl:9: error: Box.deserialize override keyword present but no superclass method matches signature to override
internal error: assertion error [resolution/cleanups.cpp:758]

Looking into this, @benharsh found that this is because the compiler creates a copy of the class type for each instantiation of the containing generic procedure, but fails to set up its parent class to point to RootClass (and, more generally, that this happens when creating any copy of a class AggregateType). As a result, the compiler-generated serialize/deserialize routines, which are declared with override markings are triggering this error since the parent class doesn't exist and nothing is being overridden. Presumably the fix is to make sure that copies of classes maintain the original class's parent class (RootClass in my case).

Is this issue currently blocking your progress?

No, in my case, I could hoist the class to the module scope in which case it works fine. It may also be possible to work around the issue by defining explicit serialize/deserialize routines, though I didn't try this (and other problems may ensue due to the lack of a proper parent class, I imagine).

Steps to Reproduce

Source Code:

proc foo(X) {
  /* doesn't work: */
  class Box {
    var val;
  }

  var b = new Box(X);
}

foo(10);

Compile command:
chpl testit.chpl

Associated Future Test(s):
test/classes/nested/nested-class-serialize-bug.chpl #27995

Configuration Information

  • Output of chpl --version: chpl version 2.7.0 pre-release (380d942188a)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions