#ifTrue: within a loop not working

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

#ifTrue: within a loop not working

John Trinder
If I evaluate

1 to: 3 do: [ :i |  i = 2  ifTrue: []].

in a w'space I get a walkback saying that 'True does not understand #<='

Am I blind or am I missing something obvious?


Reply | Threaded
Open this post in threaded view
|

Re: #ifTrue: within a loop not working

Ian Bartholomew-13
John,

> 1 to: 3 do: [ :i |  i = 2  ifTrue: []].
>
> in a w'space I get a walkback saying that 'True does not understand #<='
>
> Am I blind or am I missing something obvious?

It's caused by a longstanding problem where the compiler gets a bit confused
when optimising an #ifTrue: statement with an empty block.  From a post by
Blair, 13/12/99

-~-~-~-~-~

Its a compiler bug that occurs when empty #ifTrue:[ifFalse:] statements
occur inside an optimized to:do: loop. Inspecting the bytecodes shows that
the compiler has optimized away the redundant conditional, but failed to pop
the result of the condition expression. It seems that this only happens when
the compiler thinks it can remove the #ifTrue:[ifFalse:].

-~-~-~-~-~

If you put a statement inside the block, as you normally would, it works as
expected.

Regards
    Ian