pharo icon indicating copy to clipboard operation
pharo copied to clipboard

Cannot rename a class instance var: RBRenameInstanceVariableRefactoring can not deal with class instance variables

Open demarey opened this issue 1 year ago • 1 comments

Bug description Cannot rename a class instance variable

To Reproduce Steps to reproduce the behavior:

  1. Define a class
Object << #Foo
	classSlots: { #Default };
	package: 'ToRemove';
	install
  1. Open the browser on #Foo class on class side
  2. Select #Default and right-click to choose rename
  3. put a new name
  4. See error

Screenshots Capture d’écran 2024-06-14 à 09 16 28

Pharo-12.0.0+SNAPSHOT.build.1513.sha.ee8b9dea9b3bbc42dbcc5efca62ee8de39633f9e

demarey avatar Jun 14 '24 07:06 demarey

I think the Code just can not yet handle class instance variables (aka class side slots). It uses RBRenameInstanceVariableRefactoring, but the condisoon checking there uses the name of the class:

applicabilityPreconditions
	^ {
		  (ReIsValidInstanceVariableName name: newName).
		  (ReDefinesInstanceVariableCondition
			   classNamed: class name
			   inModel: self model
			   instanceVariables: { variableName }).
		  (ReIsVariableNotDefinedInHierarchy name: newName class: class).
		  (ReNameIsGlobalCondition new model: self model className: newName)
			  not }

The class it "Foo class", but if we ask for #name we get Foo, which then means that the check looks for instance side ivars, not class side.

ReDefinesInstanceVariableCondition has be refactored to not use names or it needs in addition a flag that the name should be interpreted as the class side.

MarcusDenker avatar Aug 27 '24 13:08 MarcusDenker