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

RB - RBTrait DNU asTraitComposition *and* cannot be created easily in RBNamespace #16593

Open
badetitou opened this issue May 7, 2024 · 2 comments

Comments

@badetitou
Copy link
Member

badetitou commented May 7, 2024

Bug description
It is not possible to use a trait made in RB in another entity in the same RB environment.
(I cannot create a RBTrait named "TMyTrait", not install in the system yet, and use it in a class "MyClass")
We got an error with asTraitComposition

This feature is used by the SmaCC project.

To Reproduce
Execute the following code

namespace := RBNamespace new.
change := namespace smaccDefineTrait: [ :builder |
	builder
		name: #TMyTrait;
		package: #HelloWorld;
		beTrait ].

(namespace classNamed: #TMyTrait). "rb-TMyTrait"

namespace defineClass: [ :builder |
	builder
		name: #MyClass;
		traits: { (namespace classNamed: #TMyTrait) };
		package: #HelloWorld ]

You'll notice the method smaccDefineTrait: which is a copy of RBNamespace>>#defineClass: but adapted to create RBTrait (because their is no method to create RBTrait too.

To avoid searching, here is the implementation of RBNamespace>>#smaccDefineTrait: for Pharo12

smaccDefineTrait: aBuilderBlock
	| change newClass newClassName |
	change := changes defineClass: aBuilderBlock.
	newClassName := change changeClassName.
	newClass := self classNamed: newClassName. 
	newClass
		ifNil: [ | newMetaclass |
			self unmarkAsRemoved: newClassName.
			newClass := self rbTraitClass named: newClassName.
			newMetaclass := self rbTraitedMetaclassClass named: newClassName.
			newClass model: self.
			newMetaclass model: self.
			newClasses
				at: newClassName
				put: (Array with: newClass with: newMetaclass) ].
	newClass superclass: nil.
	self rootClasses add: newClass.
	newClass classSide superclass: nil.
	newClass instanceVariableNames: #().
	newClass classVariableNames: #().
	newClass poolDictionaryNames: #().
	newClass packageName: change package.
	^ change

Expected behavior
I believe we should be able to deal with Trait easily in RB and the asTraitComposition should work

Version information:

  • OS: ArchLinux
  • Version: rolling
  • Pharo Version 12

Expected development cost
I don't know, but I can help to reproduce the issue.

@Ducasse
Copy link
Member

Ducasse commented May 8, 2024

Pay attention RB never worked with traits.

@badetitou
Copy link
Member Author

Is it something we want? ( Making RB dealing with Traits )
( I know it can require too much time and so the community has to work on it )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants