[squeak-dev] The Trunk: Compiler-mt.488.mcz

commits at source.squeak.org commits at source.squeak.org
Mon Jan 16 09:58:13 UTC 2023


Marcel Taeumel uploaded a new version of Compiler to project The Trunk:
http://source.squeak.org/trunk/Compiler-mt.488.mcz

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

Name: Compiler-mt.488
Author: mt
Time: 16 January 2023, 10:58:13.619631 am
UUID: 7a68fea4-14a2-2646-9114-b2189c15a869
Ancestors: Compiler-mt.487

Adds simple way to interactively warn the user about variable shadowing. Disabled by default.

In the future, it would be nice to be able to interactively edit the shadowed name such as for syntax errors.

I will enable this in my environment as I do not keep track of the Transcript when writing code. :-)

=============== Diff against Compiler-mt.487 ===============

Item was changed:
  Notification subclass: #ShadowedVariableNotification
  	instanceVariableNames: 'name selector class'
+ 	classVariableNames: 'EnableInteractiveWarning'
- 	classVariableNames: ''
  	poolDictionaries: ''
  	category: 'Compiler-Support'!
  
  !ShadowedVariableNotification commentStamp: 'ct 2/7/2022 22:18' prior: 0!
  I tell interested exception handlers or the Transcript about an attempt to compile a method with a shadowed variable, i.e., a temporary variable that has the same name as an existing instance variable in the subject class. The use and usage of shadowed variables are generally disputed: They can lead to confusion when a temporary variable declaration is missed, but they can also be utilized to make an instance variable unaccessible in a local scope.!

Item was added:
+ ----- Method: ShadowedVariableNotification class>>enableInteractiveWarning (in category 'preferences') -----
+ enableInteractiveWarning
+ 	<preference: 'Interactive warning for shadowed variable'
+ 		category: #Compiler
+ 		description: 'When enabled, notify the user interactively about a shadowed variable name. When disabled, just log the incident on the Transcript.'
+ 		type: #Boolean>
+ 	^ EnableInteractiveWarning ifNil: [false]!

Item was added:
+ ----- Method: ShadowedVariableNotification class>>enableInteractiveWarning: (in category 'preferences') -----
+ enableInteractiveWarning: aBoolean
+ 
+ 	EnableInteractiveWarning := aBoolean.!

Item was changed:
  ----- Method: ShadowedVariableNotification>>defaultAction (in category 'handling') -----
  defaultAction
  
+ 	self messageText: ('{1} ({2} is shadowed)' translated format:
- 	Transcript showln: ('{1} ({2} is shadowed)' translated format:
  		{self methodClass name , '>>' , self selector.
+ 		self variableName}).
+ 	self class enableInteractiveWarning
+ 		ifTrue: [UnhandledWarning signalForException: self "See Warning >> #defaultAction"]
+ 		ifFalse: [Transcript showln: self messageText].!
- 		self variableName}).!



More information about the Squeak-dev mailing list