Skip to content

RGElementDefinition>>realParent corrupts the model #18440

@akgrant43

Description

@akgrant43

Bug description

The definition of realParent was modified in 6da2654 to unconditionally change the parent.

The comment is just Refactor notNil ifTrue:, however looking at the definitions of parent and realParent in Pharo11 and Pharo13 it looks to me like the intention is that:

  • parent returns the parent model, i.e. another RGDefinition. If it hasn't been explicitly set, it is nil.
  • realParent returns the actual object in the image, e.g. for a RGMethodDefinition the actual class.

This is further supported by the parameter name in the setter parent: aRGBehaviorDefinition.

Thus setting the parent is incorrect and realParent should be:

realParent
	"Retrieves the Class/Trait/.. object in the System corresponding to the class of the this element."
	| realParent |

	realParent := parent
		          ifNotNil: [ parent realClass ]
		          ifNil: [ self rootEnvironment classNamed: self parentName ].
	realParent ifNil: [ ^ nil ].

	self isMeta ifTrue: [ realParent := realParent classSide ].
	
	^ realParent

This current behaviour can have real-world impact if the image is modified to access the realParent prior to the epicea file being written. In this case, as an example, creating a new class with one or more methods and then quitting the image without saving will result in an epicea file that cannot be loaded due the parent not existing when the file is loaded, triggering a STON exception. This issue doesn't exist in Pharo11 (prior to the commit referenced above).

To Reproduce

  1. Modify EpMethodModification>>#initializeWithOldMethod:newMethod: to access realParent:
initializeWithOldMethod: anOldMethod newMethod: aNewMethod

	self initialize.
	oldMethod := anOldMethod asEpiceaRingDefinition.
	newMethod := aNewMethod asEpiceaRingDefinition.

	"This triggers the issue.
	Our actual change is related to enabling grouping of extension methods by package and is much larger."
	self newMethod realParent.
  1. Create a new temporary class.
  2. Add a method to the class.
  3. Modify the method.
  4. Quit the image without saving.
  5. Restart the image and attempt to replay changes.

Expected behavior

The ombu files don't reference parent and load successfully.

Screenshots
N/A

Version information:

  • OS: NixOS
  • Version: 25.05
  • Pharo Version: Pharo12, Pharo13

Expected development cost

PR on the way.

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions