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

Trait: Overriden class side methods not added to classes using traits #3158

Open
chisandrei opened this Issue Apr 10, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@chisandrei
Copy link

chisandrei commented Apr 10, 2019

The code below creates a trait and adds two class side methods and two instance side methods:

Trait named: #TraitForTest
	 uses: {}
	 category: 'AAA'.
	
TraitForTest compile: 'ffiLibraryName
	^ 1+1. ' classified: 'test' .
	
TraitForTest compile: 'anotherMethod
	^ 1+1. ' classified: 'test' .
	
TraitForTest classTrait compile: 'ffiLibraryName
	^ 2+3. ' classified: 'test' .
	
TraitForTest classTrait compile: 'anotherMethod
	^ 2+3. ' classified: 'test' .

The class side method #ffiLibraryName is also defined in Object.

When creating then a class using that trait, the class side method #ffiLibraryName is not added to the class.

Object subclass: #ClassWithTrait
	uses: TraitForTest
	instanceVariableNames: ''
	classVariableNames: ''
	package: 'AAA'.

ClassWithTrait ffiLibraryName.

The call to #ffiLibraryName raises an exception as the method defined in Object ends up being called: "'SubclassResponsibility: ClassWithTrait class had the subclass responsibility to implement #ffiLibraryName'".

Running ClassWithTrait anotherMethod. works ok and returns 5.

Checking selectors shows that the method #ffiLibraryName is not added to the class.

ClassWithTrait includesSelector: #ffiLibraryName.  "true"
ClassWithTrait class includesSelector: #ffiLibraryName.  "false"
ClassWithTrait class includesSelector: #anotherMethod.  "true"

TraitForTest includesSelector: #ffiLibraryName. "true"
TraitForTest classTrait includesSelector: #ffiLibraryName.  "true"

Same behaviour in Pharo 7 and 8.

@khinsen

This comment has been minimized.

Copy link
Contributor

khinsen commented Apr 11, 2019

I came here to exactly this bug, only to find it reported a day earlier.

There is a potentially useful observation I can add to this. If you remove ffiLibraryName from TraitForTest after defining ClassWithTrait, and then define it again, then ClassWithTrait ffiLibraryName will work as expected. I have been using that as a workaround to continue working on my code.

khinsen added a commit to activepapers/activepapers-pharo that referenced this issue Apr 11, 2019

syrel added a commit to feenkcom/oswindow-glutin that referenced this issue Apr 11, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.