<div dir="ltr">Hi Juraj,<br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 14, 2015 at 4:56 PM, Juraj Kubelka <span dir="ltr">&lt;<a href="mailto:juraj.kubelka@gmail.com" target="_blank">juraj.kubelka@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hi,<div><br></div><div>I have a test case like that: </div><div>-=-=-</div><div><div>testIncrementBy</div><div><span style="white-space:pre-wrap">        </span>prefix := MyObject new numbers: #(1 10); yourself.</div><div><span style="white-space:pre-wrap">        </span>prefix incrementBy: 10.</div><div><span style="white-space:pre-wrap">        </span>self assert: prefix numbers equals: #(1 20).</div></div><div>-=-=-</div><div><br></div><div>and the byte code starts like that:</div><div>-=-=-</div><div><div>57 &lt;40&gt; pushLit: MyObject</div><div>58 &lt;CC&gt; send: new</div><div>59 &lt;88&gt; dup</div><div>60 &lt;21&gt; pushConstant: #(1 10)</div></div><div>-=-=-</div><div><br></div><div>If I run the test case, it is green, but the byte code changes into:</div><div>-=-=-</div><div><div>57 &lt;40&gt; pushLit: MyObject</div><div>58 &lt;CC&gt; send: new</div><div>59 &lt;88&gt; dup</div><div>60 &lt;21&gt; pushConstant: #(1 <b>20</b>)</div></div><div>-=-=-</div><div><br></div><div>The #incrementBy: method looks like:</div><div>-=-=-</div><div>incrementBy: aNumber</div><div><span style="white-space:pre-wrap">        </span>numbers at: 2 put: (numbers at: 2) + aNumber</div><div>-=-=-</div><div><br></div><div>Is it correct that it also changes the method byte code? </div></div></blockquote><div><br></div><div>No, ut this does happen.  hat I suspect you&#39;re seeing is the fact that in the Pharo and Squeak implementations, literals are not immutable.  So if you were to assign to a literal Array in a method&#39;s literals that assignment would not cause an error, and worse, would not be visible because the mehtods source code would be unchanged.</div><div><br></div><div>We shall have a proper fix for this in a future release where we will support fully immutable literals.  For now the correct respponse shoudl be to find out where in your code the literal is assigned to and to not do that.  Of course adding a copy is also fine.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>I can put &quot;#(1 10) copy” into the test case. </div><div>I am just curious if it is a feature or bug. </div></div></blockquote><div><br></div><div>It&#39;s a bug, but an ancient one.  Some Smalltalks, such as VisualAge and VisualWorks have fixed this by introducing support for immutable objects, but the {haro/Squeak Vms have yet to provide this.  I expect to implement it in Spur some time next year.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div>Tested in Pharo4.0, Latest update: #40613.</div><div><br></div><div>Cheers,</div><div>Juraj</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div>
</div></div>