-
-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix metaclass of a class after removing its traits
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
- Loading branch information
Showing
3 changed files
with
82 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
Class { | ||
#name : 'ShTraitInstallerTest', | ||
#superclass : 'ShClassInstallerTest', | ||
#category : 'Traits-Tests-ShiftClassInstaller', | ||
#package : 'Traits-Tests', | ||
#tag : 'ShiftClassInstaller' | ||
} | ||
|
||
{ #category : 'tests' } | ||
ShTraitInstallerTest >> testCreatingFullTraitHasAllElements [ | ||
|
||
newClass := ShiftClassInstaller make: [ :builder | | ||
builder | ||
beTrait; | ||
name: #TSHClass; | ||
slots: { #a. #b }; | ||
traits: { TViewModelMock }; | ||
tag: 'boring'; | ||
package: self generatedClassesPackageName ]. | ||
|
||
self assert: newClass name equals: #TSHClass. | ||
self assert: newClass slots size equals: 2. | ||
self assert: newClass slotNames equals: #( a b ). | ||
self assert: newClass traitComposition equals: { TViewModelMock } asTraitComposition. | ||
self assert: newClass class traitComposition equals: { TViewModelMock classSide } asTraitComposition. | ||
self assert: newClass package name equals: self generatedClassesPackageName. | ||
self assert: newClass packageTag name equals: 'boring' | ||
] | ||
|
||
{ #category : 'tests' } | ||
ShTraitInstallerTest >> testRemovingTraitCompositionOfAClassAfterFillForShouldUpdateItsMetaclass [ | ||
|
||
| t1 | | ||
t1 := ShiftClassInstaller make: [ :builder | | ||
builder | ||
name: #TShCITestClass; | ||
beTrait; | ||
package: self generatedClassesPackageName ]. | ||
|
||
newClass := ShiftClassInstaller make: [ :builder | | ||
builder | ||
name: #ShCITestClass; | ||
traits: t1; | ||
package: self generatedClassesPackageName ]. | ||
|
||
self assert: newClass class class equals: TraitedMetaclass. | ||
|
||
newClass := ShiftClassInstaller make: [ :builder | | ||
builder | ||
fillFor: newClass; | ||
traits: { } ]. | ||
|
||
self assert: newClass class class equals: Metaclass | ||
] | ||
|
||
{ #category : 'tests' } | ||
ShTraitInstallerTest >> testRemovingTraitCompositionOfAClassShouldUpdateItsMetaclass [ | ||
|
||
| t1 | | ||
t1 := ShiftClassInstaller make: [ :builder | | ||
builder | ||
name: #TShCITestClass; | ||
beTrait; | ||
package: self generatedClassesPackageName ]. | ||
newClass := ShiftClassInstaller make: [ :builder | | ||
builder | ||
name: #ShCITestClass; | ||
traits: t1; | ||
package: self generatedClassesPackageName ]. | ||
|
||
self assert: newClass class class equals: TraitedMetaclass. | ||
|
||
newClass := ShiftClassInstaller make: [ :builder | | ||
builder | ||
name: #ShCITestClass; | ||
package: self generatedClassesPackageName ]. | ||
|
||
self assert: newClass class class equals: Metaclass | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters