<div dir="ltr">This is not a bug.<div><br><div style>Here your variable methodScope is defined outside the block, therefore all the blocks and the method refers to the same variable when calling methodScope.</div><div style>
<br></div><div style>Your code is the same as if you wrote :</div><div style>| methodScope |</div><div style>methodScope := 1. </div><div style>methodScope := 2.</div><div style>At the end, methodScope is of course 2.</div>
<div style><br></div><div style>If you want the result :</div><div style>1</div><div style>2</div><div style>you have to declare the variable in the block (then there are different variable named methodScope, actually 1 per activation of the block.</div>
<div style><br></div><div style>collection := OrderedCollection new.<br>1 to: 2 do: [ :index |</div><div style>        | methodScope |<br>        methodScope := index.<br>        dict add: [ methodScope ] ].<br>collection do: [ :block | Transcript show: block value; cr ]<br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/8/2 Max Leske <span dir="ltr">&lt;<a href="mailto:maxleske@gmail.com" target="_blank">maxleske@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
I just came across this (possible) bug and I&#39;m able to reproduce it in Pharo 2.0 and 3.0 with the latest PharoVM (found in a 1.3 with NBCog):<br>
<br>
expected (by my feeble mind):<br>
1<br>
2<br>
<br>
actual:<br>
2<br>
2<br>
<br>
| methodScope |<br>
collection := OrderedCollection new.<br>
1 to: 2 do: [ :index |<br>
        methodScope := index.<br>
        dict add: [ methodScope ] ].<br>
<br>
collection do: [ :block | Transcript show: block value; cr ]<br>
<br>
I&#39;m aware that using method temps in this way is not good programming style (usually) but I still think this behavior is curious if not at least very likely to cause a lot of weird errors.<br>
<br>
Should I open a bug report?<br>
<br>
Cheers,<br>
Max</blockquote></div><br></div></div></div>