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

Cannot use slot as class variable: Raise explicit error #4314

Closed
jecisc opened this issue Aug 13, 2019 · 2 comments

Comments

@jecisc
Copy link
Member

commented Aug 13, 2019

I tried to make BalloonEngine class variables BufferCache a WeakSlot but I got an error:

WeakSlot(Object)>>doesNotUnderstand: #asClassVariable
[ :e | e asClassVariable ] in ShiftClassBuilder>>sharedVariables: in Block: [ :e | e asClassVariable ]
Array(SequenceableCollection)>>collect:
ShiftClassBuilder>>sharedVariables:
[ :builder | 
builder
	name: aSubclassSymbol;
	superclass: self;
	slots: slotDefinition;
	sharedVariables: classVarDefinition;
	sharedPools: someSharedPoolNames;
	category: aCategorySymbol ] in Object class(Class)>>subclass:slots:classVariables:poolDictionaries:package: in Block: [ :builder | ...
ShiftClassInstaller>>make:
ShiftClassInstaller class>>make:
Object class(Class)>>subclass:slots:classVariables:poolDictionaries:package:
UndefinedObject>>DoIt
OpalCompiler>>evaluate
ClySystemEnvironment>>compileANewClassFrom:notifying:startingFrom:
ClyFullBrowser>>compileANewClassFrom:notifying:startingFrom:
ClyClassDefinitionEditorToolMorph>>applyChanges

This might interest you @MarcusDenker

@MarcusDenker

This comment has been minimized.

Copy link
Member

commented Aug 14, 2019

Class Variables and Slots are two different entities: You can not use a Slot as a class variable.

(this might be possible to unify later, but even then this unified variable would need to implement different code for both the slot or the class var case and might be done via some additional layer,
the objects representing a variable inside an object vs. one in the class will have to be different as their API is different and the data they need is different....)

This means, if you want to have a "Weak Class Variable" you have to implement this, see ExampleClassVariable as an example.

I will add code to detect when people try to use slots as class vars and raise a nice error message.

@MarcusDenker MarcusDenker changed the title Cannot use slot as class variable Cannot use slot as class variable: Raise explicit error Aug 14, 2019

@MarcusDenker

This comment has been minimized.

Copy link
Member

commented Aug 14, 2019

Sadly I can not commit as my image does not allow me to make PRs (I press on "Ok" and nothing happens)

What needs to be done: add this method to Slot:

asClassVariable
self error: 'Slots can not be used to define Class Variables, you need to create a LiteralVariable subclass instead'

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