Skip to content

[Backport] Port fixes on traits and metaclasses to Pharo 12#16776

Merged
MarcusDenker merged 7 commits intopharo-project:Pharo12from
jecisc:backport-traits-fixes
Jun 20, 2024
Merged

[Backport] Port fixes on traits and metaclasses to Pharo 12#16776
MarcusDenker merged 7 commits intopharo-project:Pharo12from
jecisc:backport-traits-fixes

Conversation

@jecisc
Copy link
Member

@jecisc jecisc commented Jun 16, 2024

Backport fixes of #16739 and #16722

jecisc added 6 commits June 16, 2024 18: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
Imagine you have two traits T1 and T2. You also have a class C1 using T1 and a class C2 subclassing C1 and using T2.
Now if you remove T1 from C1 a bug causes C2 to also lose its trait T2.

The bug comes from the fact that in the trait implementation we copy methods from TraitedMetaclass and TraitedClass in the class using traits. But only in the top most class. Thus, if we update the superclass and it does not have the traits methods anymore, then all subclasses also loses this API.

My proposed fix is to keep a flag to know if a class update makes it go from a TraitedMetaclass to another metaclass class and if this flag is true, we update the method dictionaries of the subclasses to get the methods from TraitedMetaclass and TraitedClass.

I added a test to check this
@jecisc jecisc marked this pull request as draft June 16, 2024 16:40
@jecisc jecisc marked this pull request as ready for review June 18, 2024 09:05
@MarcusDenker MarcusDenker merged commit aa50f9c into pharo-project:Pharo12 Jun 20, 2024
@jecisc jecisc deleted the backport-traits-fixes branch July 18, 2024 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants