Skip to content

Commit

Permalink
Merge pull request #1730 from tesonep/22271-Fix-IndexedSlots-in-combi…
Browse files Browse the repository at this point in the history
…nation-with-StatefulTraits-

22271-Fix-IndexedSlots-in-combination-with-StatefulTraits-
  • Loading branch information
estebanlm committed Oct 1, 2018
2 parents 11ff7c3 + 2d250da commit a787b88
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 13 deletions.
14 changes: 7 additions & 7 deletions src/Kernel-Tests/ClassHierarchyTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ ClassHierarchyTest class >> fixSubclasses [

{ #category : #tests }
ClassHierarchyTest >> testObjectFormatInstSize [
| classes |
| classes offending |
"check that #instSize is in sync with #allInstVarNames"
self assert:
(SystemNavigation default allBehaviors
allSatisfy: [ :cls | cls instSize = cls allInstVarNames size ]).
offending := SystemNavigation default allBehaviors reject: [ :cls | cls instSize = (cls allSlots reject: #isVirtual) size ].
self assertCollection: offending hasSameElements: {}.

"instSpec is only 0 for classes without any inst vars or variable fields"
classes := SystemNavigation default allBehaviors
select: [ :cls | cls isTrait not and: [ cls instSpec = 0 ] ].
self assert: (classes allSatisfy: [ :each | each instVarNames isEmpty or: [ each isVariable not ] ])
classes := SystemNavigation default allBehaviors select: [ :cls | cls isTrait not and: [ cls instSpec = 0 ] ].
offending := classes reject: [ :each | each instVarNames isEmpty or: [ each isVariable not ] ].
self assertCollection: offending hasSameElements: {}.

]

{ #category : #tests }
Expand Down
2 changes: 0 additions & 2 deletions src/Shift-ClassInstaller/ShiftClassInstaller.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ ShiftClassInstaller >> fixSlotScope: newClass [
newClass superclass ifNil: [ ^ self ].
(newClass classLayout slotScope isKindOf: LayoutEmptyScope) ifTrue: [ ^ self ].

self assert: newClass superclass classLayout slotScope = newClass classLayout slotScope parentScope.

newClass superclass classLayout slotScope == newClass classLayout slotScope parentScope
ifFalse: [ newClass classLayout slotScope parentScope: newClass superclass classLayout slotScope ].

Expand Down
22 changes: 22 additions & 0 deletions src/TraitsV2-Tests/T2TraitWithSlots.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@ T2TraitWithSlots >> createT1 [
^ t1
]

{ #category : #tests }
T2TraitWithSlots >> testClassUsingStatefulTraits [

| t1 c1 |

t1 := self newTrait: #T1 with: #(aSlot).
c1 := self newClass: #C1 superclass: Object with: #() uses: { t1 }.

self assert: c1 slots isEmpty
]

{ #category : #tests }
T2TraitWithSlots >> testClassUsingStatefulTraitsAndLocalSlots [

| t1 c1 |

t1 := self newTrait: #T1 with: #(aSlot).
c1 := self newClass: #C1 superclass: Object with: #(anotherSlot) uses: { t1 }.

self assertCollection: c1 slots hasSameElements: { c1 slotNamed: #anotherSlot }
]

{ #category : #tests }
T2TraitWithSlots >> testDefiningClass [

Expand Down
4 changes: 2 additions & 2 deletions src/TraitsV2/TaClassCompositionElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ TaClassCompositionElement >> selectors [

{ #category : #accessing }
TaClassCompositionElement >> slots [
^ innerClass slots
reject: [ :e | TraitedClass slots anySatisfy: [ :x | x name = e name ] ]
^ innerClass allSlots
reject: [ :e | TraitedClass allSlots anySatisfy: [ :x | x name = e name ] ]

]

Expand Down
2 changes: 1 addition & 1 deletion src/TraitsV2/TaCompositionElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ TaCompositionElement >> selectors [

{ #category : #accessing }
TaCompositionElement >> slots [
^ innerClass slots
^ innerClass allSlots
]

{ #category : #printing }
Expand Down
6 changes: 5 additions & 1 deletion src/TraitsV2/TraitedClass.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,11 @@ TraitedClass >> removeSelector: aSelector [
{ #category : #initialization }
TraitedClass >> slots [
"I remove the slots comming from a traitComposition"
^ super slots reject:[ :e | self traitComposition slots includes:e ]

^ super slots reject:
[ :aSlot |
self traitComposition slots anySatisfy:
[ :existingSlots | aSlot name = existingSlots name ] ]
]

{ #category : #'accessing tags' }
Expand Down

0 comments on commit a787b88

Please sign in to comment.