Hello,

I am trying to load Ring into GemStone.
As Ring uses traits, the first thing I did was flatten the traits.

Based on a thread on this mailing list from June 2011 (Elliot flattening the 
traits in Fuel) I used Behavior>flattenDownAllTraits.

One thing I noticed is that, while this method successfully flattens the 
instance methods of the trait, the class methods appear to be just removed.

I was able to fix this by changing method Behavior>>flattenDown.
Before this method was implemented as:
flattenDown: aTrait
        | selectors |
        [self hasTraitComposition and: [self traitComposition allTraits 
includes: aTrait]] assert.
        selectors := (self traitComposition transformationOfTrait: aTrait) 
selectors.
        self basicLocalSelectors: self basicLocalSelectors , selectors.
        self removeFromComposition: aTrait.

My guess is that the culprit for this is the method 
Behavior>>removeFromComposition:, which removes the trait both from the 
instance and the class side.
While the trait selectors were added to the instance side, they are not to the 
class side and therefore they are gone after the flattening.

I was able to fix this by changing the method to:
flattenDown: aTrait
        | selectors classSelectors transformation classTransformation |
        [self hasTraitComposition and: [self traitComposition allTraits 
includes: aTrait]] assert.
        transformation := self traitComposition transformationOfTrait: aTrait.
        selectors := transformation selectors.
        classSelectors := classTransformation selectors.
        self basicLocalSelectors: (self basicLocalSelectors ifNil:[selectors] 
ifNotNil:[:bs | bs, selectors]).
        self class basicLocalSelectors: (self class basicLocalSelectors 
ifNil:[classSelectors] ifNotNil:[:bs | bs, classSelectors]).
        self removeFromComposition: aTrait.

My fix feels more like a workaround than a real solution to the problem, so 
before that I submit a patch to the inbox I was wondering if someone with more 
knowledge regarding the traits implementation has any input on this ...


Cheers,

Andy


Reply via email to