[squeak-dev] The Inbox: Kernel.dve-fbs.831.mcz

commits at source.squeak.org commits at source.squeak.org
Mon Jan 6 13:31:27 UTC 2014


A new version of Kernel was added to project The Inbox:
http://source.squeak.org/inbox/Kernel.dve-fbs.831.mcz

==================== Summary ====================

Name: Kernel.dve-fbs.831
Author: fbs
Time: 6 January 2014, 1:30:13.195 pm
UUID: b4878bfa-b720-b94c-9166-091e0d074a89
Ancestors: Kernel-fbs.829

If a subclass contains an inst var named 'foo' and you try add a same-named inst var to a superclass, you get a very unhelpful error message. This attempts to tell you which inst vars conflict (in case there are several), and in which subclass the inst vars already exist.

(It doesn't handle all cases: if you have 'foo' in SubclassA and 'bar' in SubclassB, your error message will complain about only the first conflict.)

=============== Diff against Kernel-fbs.829 ===============

Item was changed:
  ----- Method: ClassBuilder>>validateInstvars:from:forSuper: (in category 'validation') -----
  validateInstvars: instVarArray from: oldClass forSuper: newSuper
  	"Check if any of the instVars of oldClass conflict with the new superclass"
+ 	| usedNames temp |
- 	| instVars usedNames temp |
  	instVarArray isEmpty ifTrue:[^true]. "Okay"
  	newSuper allowsSubInstVars ifFalse: [
  		self error: newSuper printString, ' does not allow subclass inst vars. See allowsSubInstVars.'. ^ false].
  
  	"Validate the inst var names"
  	usedNames := instVarArray asSet.
  	usedNames size = instVarArray size 
  		ifFalse:[	instVarArray do:[:var|
  					usedNames remove: var ifAbsent:[temp := var]].
  				self error: temp,' is multiply defined'. ^false].
  	(usedNames includesAnyOf: self reservedNames) 
  		ifTrue:[	self reservedNames do:[:var|
  					(usedNames includes: var) ifTrue:[temp := var]].
  				self error: temp,' is a reserved name'. ^false].
  
  	newSuper == nil ifFalse:[
  		usedNames := newSuper allInstVarNames asSet.
  		instVarArray do:[:iv|
  			(usedNames includes: iv) ifTrue:[
  				newSuper withAllSuperclassesDo:[:cl|
  					(cl instVarNames includes: iv) ifTrue:[temp := cl]].
  				(DuplicateVariableError new)
  					superclass: temp;
  					variable: iv;
  					signal: iv,' is already defined in ', temp name]]].
+ 	oldClass == nil ifFalse:[ | dups conflicts |
+ 		dups := oldClass subclasses collect: [:cls | {cls. cls instVarNames}].
+ 		dups
+ 			detect: [:data | conflicts := data second intersection: instVarArray. conflicts notEmpty]
+ 			ifFound: [:data |
+ 				DuplicateVariableError new
- 	oldClass == nil ifFalse:[
- 		usedNames := Set new: 20.
- 		oldClass allSubclassesDo:[:cl| usedNames addAll: cl instVarNames].
- 		instVars := instVarArray.
- 		newSuper == nil ifFalse:[instVars := instVars, newSuper allInstVarNames].
- 		instVars do:[:iv|
- 			(usedNames includes: iv) ifTrue:[
- 				(DuplicateVariableError new)
  					superclass: oldClass;
+ 					variable: conflicts first;
+ 					signal: ('{1} {2} in {3}' format: {conflicts asCommaString. conflicts size > 1 ifTrue: ['are'] ifFalse: ['is']. data first})]
+ 			ifNone: [nil]].
- 					variable: iv;
- 					signal: iv,' is already defined in a subclass of ', temp name]]].
  	^true!



More information about the Squeak-dev mailing list