[squeak-dev] The Trunk: Compiler-nice.321.mcz

commits at source.squeak.org commits at source.squeak.org
Tue May 3 07:03:31 UTC 2016

Nicolas Cellier uploaded a new version of Compiler to project The Trunk:

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

Name: Compiler-nice.321
Author: nice
Time: 3 May 2016, 9:02:56.110078 am
UUID: fd182984-c3ab-4477-bbff-44d9b1744ee3
Ancestors: Compiler-nice.320

Be pedantic: refuse to compile until the user eliminate dead code following a returning if (case when both branches return).
Do this only when interactive, we don't like when Compiler refuses to load legacy code.

=============== Diff against Compiler-nice.320 ===============

Item was changed:
  ----- Method: Parser>>statements:innerBlock:blockNode: (in category 'expression types') -----
  statements: argNodes innerBlock: inner blockNode: theBlockNode
  	| stmts returns start |
  	"give initial comment to block, since others trail statements"
  	theBlockNode comment: currentComment.
  	currentComment := nil.
  	stmts := OrderedCollection new.
  	returns := false.
  	hereType ~~ #rightBracket ifTrue:
  		[[theBlockNode startOfLastStatement: (start := self startOfNextToken).
  		  (returns := self matchReturn)
  				[self expression ifFalse:
  					[^self expected: 'Expression to return'].
  				 self addComment.
  				 stmts addLast: (parseNode isReturningIf
  								ifTrue: [parseNode]
  								ifFalse: [ReturnNode new
  											expr: parseNode
  											encoder: encoder
  											sourceRange: (start to: self endOfLastToken)])]
  				[self expression
  						[self addComment.
+ 						"if both branches return, following code is unreachable, let's avoid this.
+ 						But only if interactive, we don't want to prevent loading of legacy code"
+ 						self interactive ifTrue: [returns := parseNode isReturningIf].
  						 stmts addLast: parseNode]
  						[self addComment.
  						 stmts size = 0 ifTrue: 
  							[stmts addLast: 
  								(encoder encodeVariable:
  									(inner ifTrue: ['nil'] ifFalse: ['self']))]]].
  		  returns ifTrue: 
  			[self match: #period.
  			 (hereType == #rightBracket or: [hereType == #doIt]) ifFalse:
  				[^self expected: 'End of block']].
  		  returns not and: [self match: #period]] whileTrue].
  		arguments: argNodes
  		statements: stmts
  		returns: returns
  		from: encoder.
  	parseNode := theBlockNode.

More information about the Squeak-dev mailing list