Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some announcements are not signaled on class changes #14987

Open
j-brant opened this issue Oct 12, 2023 · 0 comments
Open

some announcements are not signaled on class changes #14987

j-brant opened this issue Oct 12, 2023 · 0 comments

Comments

@j-brant
Copy link
Contributor

j-brant commented Oct 12, 2023

Bug description
If you have a traited class, sometimes class changes are not signaled through the SystemAnnouncer

To Reproduce
Evaluate/inspect this code:

| announcements |
Object subclass: #T1
	instanceVariableNames: ''
	classVariableNames: ''
	package: 'TestPackage'.
#T1 asClass subclass: #T2
	uses: TOne
	instanceVariableNames: ''
	classVariableNames: ''
	package: 'TestPackage'.
#T1 asClass subclass: #T3
	instanceVariableNames: ''
	classVariableNames: ''
	package: 'TestPackage'.

announcements := OrderedCollection new.
SystemAnnouncer uniqueInstance weak when: ClassModificationApplied send: #add: to: announcements.

Model subclass: #T1
	instanceVariableNames: ''
	classVariableNames: ''
	package: 'TestPackage'.
	
announcements add: nil.

Object subclass: #T1
	instanceVariableNames: ''
	classVariableNames: ''
	package: 'TestPackage'.
	
SystemAnnouncer uniqueInstance unsubscribe: announcements.
announcements 

This records the ClassModificationApplied announcements during the recompile of T1 to be under Model and the changing it back to be under Object. Before the nil separator entry there are only announcements for T1 and T3. After the nil, there are announcements for all three classes (T1, T2, & T3).

Expected behavior
All three classes should appear before and after the nil entry as all three classes have been recompiled.

Version information:

  • Pharo 10, 11, & 12

Expected development cost
Here's a potential fix:

  1. Copy TraitBuilderEnhancer>>#allSlotsForBuilder: to create a TraitBuilderEnhancer>>#slotsForBuilder:
TraitBuilderEnhancer>>slotsForBuilder: aBuilder

	| resultingSlots |
	
	resultingSlots := self
		eliminateDuplicates: aBuilder layoutDefinition slots , aBuilder traitComposition asTraitComposition slotsCopy
		withSuperclassSlots: (aBuilder superclass ifNil: [#()] ifNotNil:[ :x | x allSlots]).

	^ resultingSlots
  1. Change one reference to allSlotsForBuilder: to use new method:
TraitBuilderEnhancer>>configureClass: newClass superclass: superclass withLayoutType: layoutType slots: slots
	| resultingSlots |
	self validateTraitComposition: self traitComposition ofClass: builder oldClass.

	resultingSlots := self slotsForBuilder: builder.

	newClass superclass: superclass withLayoutType: layoutType slots: resultingSlots
  1. Fix the allSlotsForBuilder: to return all slots:
TraitBuilderEnhancer>>allSlotsForBuilder: aBuilder
	| classSlots traitSlots |
	classSlots := super allSlotsForBuilder: aBuilder.
	traitSlots := aBuilder traitComposition asTraitComposition slotsCopy
			reject: [ :each | classSlots anySatisfy: [ :cs | cs name = each name ] ].
	^ classSlots , traitSlots
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants