Skip to content

Fix multiple bugs in metaclass management of ShiftClassBuilder#16722

Merged
MarcusDenker merged 4 commits intopharo-project:Pharo13from
jecisc:traits/fix-metaclass
May 31, 2024
Merged

Fix multiple bugs in metaclass management of ShiftClassBuilder#16722
MarcusDenker merged 4 commits intopharo-project:Pharo13from
jecisc:traits/fix-metaclass

Conversation

@jecisc
Copy link
Member

@jecisc jecisc commented May 30, 2024

This PR fixes multiples bugs I detected in the management of metaclasses of the ShiftClassBuilder.

  1. The first bug was appearing when we had a class using a trait and we updated it using #fillFor: in the class builder block, then we removed the trait composition. This produced a class without trait but with a TraitedMetaclass class.

  2. When using the #<< method to have the Fluid syntax, if the class had a trait in the past, it would always be produced with a TraitedMetaclass as a class even if the traits are removed.

  3. I don't know why but using #<< was always preserving the old class trait composition which could lead to some problems in case you removed a trait.

My way to fix the problem is to update the management of the metaclass class in the ShiftClassBuilder. Before it was a variable that we had to set when we were managing our traits. Now this is an information that is resolved during the class building. It is delegated to the BuilderEnhancer. Thus, it is still possible to set our own metaclass class by adding a new buider enhancer!

Fixes #16472

jecisc added 4 commits May 30, 2024 14:36
If you have a class using traits, its metaclass will be TraitedMetaclass. Now, if you remove its traits, its class should be Metaclass. The problem is that if you use #fillFor: it will not be the case.

The origin of the problem comes from the fact that #fillFor: will set the metaclass class to TraitedMetaclass and this will not be updated if you set the trait composition to be empty.

I provided a fix that is not so good in my opinion, but I'll try to change the way the class builder deals with metaclass class later to simplify this system and remove the need of this fix.

Finally I moved a test from shift class builder tests to traits tests since it uses a trait
@jecisc
Copy link
Member Author

jecisc commented May 30, 2024

This could potentially fix a random bug that make a class trait composition addition appear in Iceberg from time to time in the diff

@MarcusDenker MarcusDenker merged commit ee0fdd6 into pharo-project:Pharo13 May 31, 2024
@jecisc jecisc deleted the traits/fix-metaclass branch July 18, 2024 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Removing a trait from a class does not updates its metaclass

2 participants