Nicolas Cellier uploaded a new version of Tests to project The Trunk:
http://source.squeak.org/trunk/Tests-nice.93.mcz==================== Summary ====================
Name: Tests-nice.93
Author: nice
Time: 8 September 2010, 1:13:13.201 am
UUID: a2198d6b-fb89-4663-98c7-f8c8f82cc6de
Ancestors: Tests-ar.92
Provides two non regression tests for
http://bugs.squeak.org/view.php?id=7093- 1 for compiler
- 1 for decompiler
#to:do: optimization is wrong when the block modifies the limit
=============== Diff against Tests-ar.92 ===============
Item was added:
+ ----- Method: CompilerTest>>testToDoModifiesTheLimit (in category 'testing') -----
+ testToDoModifiesTheLimit
+ "This is a non regression test for
http://bugs.squeak.org/view.php?id=7093.
+ When blocks writes into to:do: loop limit, optimization shall be carried with care."
+
+ self
+ shouldnt:
+ [ | n |
+ n := 2.
+ 1 to: n do: [:i | (n := n+1)>10 ifTrue: [self error: 'Should not get here']].
+ n]
+ raise: Error.
+
+ self
+ assert:
+ [ | n |
+ n := 2.
+ 1 to: n do: [:i | (n := n+1)>10 ifTrue: [self error: 'Should not get here']].
+ n] value = 4.
+ self
+ assert:
+ [ | n |
+ n := 2.
+ 1 to: n by: 1 do: [:i | (n := n+1)>10 ifTrue: [self error: 'Should not get here']].
+ n] value = 4.
+ self
+ assert:
+ [ | n inc |
+ n := 2.
+ inc := 1.
+ 1 to: n by: inc do: [:i | (n := n+1)>10 ifTrue: [self error: 'Should not get here']].
+ n] value = 4!
Item was added:
+ ----- Method: DecompilerTests>>tearDown (in category 'initialize-release') -----
+ tearDown
+ self class removeSelector: #loopWithMovingLimit!
Item was added:
+ ----- Method: DecompilerTests>>testDecompileLoopWithMovingLimit (in category 'tests') -----
+ testDecompileLoopWithMovingLimit
+ "This is a non regression test for
http://bugs.squeak.org/view.php?id=7093"
+
+ | decompiledCode sourceCode |
+ sourceCode := 'loopWithMovingLimit
+ "This loop might be decompiled as a to:do: but should not because it does modify its limit"
+ | n i |
+ n := 4.
+ i := 1.
+ [i <= n] whileTrue: [
+ n := n - 1.
+ i := i + 1].
+ ^n'.
+ self
+ shouldnt: [self class compile: sourceCode]
+ raise: Error.
+ self assert: (self perform: #loopWithMovingLimit) = 2.
+ self
+ shouldnt: [decompiledCode := self class decompile: #loopWithMovingLimit]
+ raise: Error.
+ self
+ shouldnt: [self class compile: decompiledCode decompileString]
+ raise: Error.
+ self
+ assert: (self perform: #loopWithMovingLimit) = 2
+ description: 'result from decompiledCode should not differ from sourceCode'.!