diff --git a/src/Shift-ClassBuilder/ShiftClassBuilder.class.st b/src/Shift-ClassBuilder/ShiftClassBuilder.class.st index a393c77d06a..66e7a004ddc 100644 --- a/src/Shift-ClassBuilder/ShiftClassBuilder.class.st +++ b/src/Shift-ClassBuilder/ShiftClassBuilder.class.st @@ -111,10 +111,6 @@ ShiftClassBuilder >> build [ self createMetaclass. self createClass. - self oldClass ifNotNil: [ - self copyProtocols. - self newClass commentSourcePointer: self oldClass commentSourcePointer ]. - self createSharedVariables. self installSlotsAndVariables. @@ -236,6 +232,11 @@ ShiftClassBuilder >> createClass [ slots: (self withAdditionalSlots: self slots). newClass environment: self installingEnvironment. + + "Since Traits might add some methods in #classCreated:, we need to copy the protocols before we add them." + self oldClass ifNotNil: [ + self copyProtocols. + self newClass commentSourcePointer: self oldClass commentSourcePointer ]. self builderEnhancer classCreated: self ] diff --git a/src/Traits-Tests/ShTraitInstallerTest.class.st b/src/Traits-Tests/ShTraitInstallerTest.class.st index 02a470f764e..3b8bcda5c0d 100644 --- a/src/Traits-Tests/ShTraitInstallerTest.class.st +++ b/src/Traits-Tests/ShTraitInstallerTest.class.st @@ -6,6 +6,26 @@ Class { #tag : 'ShiftClassInstaller' } +{ #category : 'tests' } +ShTraitInstallerTest >> testAddingATraitToAClassHasRightProtocolsOnMetaclass [ + "Regression test. Some methods were copied on the method dic of a metaclass but the protocols were lost" + + newClass := ShiftClassInstaller make: [ :builder | + builder + name: #SHClass; + package: self generatedClassesPackageName ]. + + newClass := ShiftClassInstaller make: [ :builder | + builder + name: #SHClass; + traits: { TViewModelMock }; + package: self generatedClassesPackageName ]. + + self assert: (newClass methods allSatisfy: [ :method | method protocol isNotNil ]). + self assert: (newClass class methods allSatisfy: [ :method | method protocol isNotNil ]). + self assert: (newClass class class methods allSatisfy: [ :method | method protocol isNotNil ]) +] + { #category : 'tests' } ShTraitInstallerTest >> testCreatingFullTraitHasAllElements [