<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Amazing!</p>
    <div class="moz-cite-prefix">On 2026-10-06 4:59 AM, Nicolas Cellier
      via Cuis-dev wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAKnRiT6ibm598qF=CP5mTxtxA3e_v3rnUTWpuQARLUbMDU+HpQ@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">Gosh, I accidentally fixed it in Squeak !7 years
        before it was even noticed...<br>
        <a href="https://source.squeak.org/trunk/Kernel-nice.346.diff"
          moz-do-not-send="true" class="moz-txt-link-freetext">https://source.squeak.org/trunk/Kernel-nice.346.diff</a></div>
      <br>
      <div class="gmail_quote gmail_quote_container">
        <div dir="ltr" class="gmail_attr">Le lun. 5 oct. 2026 à 22:16,
          Juan Vuletich via Cuis-dev <<a
            href="mailto:cuis-dev@lists.cuis.st" moz-do-not-send="true"
            class="moz-txt-link-freetext">cuis-dev@lists.cuis.st</a>>
          a écrit :<br>
        </div>
        <blockquote class="gmail_quote"
style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
          <div>
            <p>Hi Facu,</p>
            <p>Wow! Not every day you find a bug that is over 40 years
              old!</p>
            <p>Just pushed this to GitHub. Thanks!</p>
            <p>Cheers,</p>
            <div>On 2026-10-04 1:01 PM, Facundo Javier Gelatti via
              Cuis-dev wrote:<br>
            </div>
            <blockquote type="cite">
              <div dir="ltr">
                <div>Hello!</div>
                <div><br>
                </div>
                <div>This is a bug report + fix.</div>
                <div><br>
                </div>
                <div>The bug is the following: declaring a class
                  instance variable from the "Unknown variable" popup
                  sometimes produces a method whose bytecode does not
                  match the source (it stores into the wrong variables).</div>
                <div>I attach some code to see this (<span
                    style="font-family:monospace"><a
                      href="http://example.workspace.st" target="_blank"
                      moz-do-not-send="true">example.workspace.st</a></span>),
                  which should be run from a workspace.</div>
                <div><br>
                </div>
                <div>This happens because <span
                    style="font-family:monospace">Metaclass>>addInstVarName:</span>
                  reverses the order of existing variables (which is
                  already a weird behavior), and the compiler resolves
                  instance variables to slot numbers at the start of the
                  compilation. So, in an interactive environment:</div>
                <div>1. When we accept a method with an undeclared name,
                  a notification is signalled mid-compilation.</div>
                <div>2. Then, from the popup, we choose to declare an
                  instance variable.</div>
                <div>3. So, <span style="font-family:monospace">Parser>>declareInstVar:</span>
                  sends <span style="font-family:monospace">#addInstVarName:</span>.
                  This adds the instance variable (reversing the order
                  of the existing ones), and triggers a recompilation of
                  all existing methods (this does not include the method
                  mid-compilation, which is not yet installed on the
                  class).</div>
                <div>4. Then the compilation resumes. But the encoder
                  has already assigned a slot index to every
                  pre-existing variable, so the system ends up producing
                  the wrong bytecode.</div>
                <div>Note that the class needs to have at least two
                  existing class instance variables for this to happen
                  (since reversing just one does nothing).</div>
                <div><br>
                </div>
                <div>The fix is to make <span
                    style="font-family:monospace">Metaclass>>addInstVarName:</span> preserve
                  the order of the variables (as <span
                    style="font-family:monospace">Class>>addInstVarName:</span>
                  already does). With the order preserved, the indices
                  the encoder computed before the declaration stay
                  valid.</div>
                <div><br>
                </div>
                <div>I've included tests for the bug, and also two
                  additional things for consistency: one test for this
                  same thing but instance-side, and a change to <span
                    style="font-family:monospace">#removeInstVarName:</span>
                  to also preserve the order of the variables (removing
                  class instance variables does not produce wrong
                  behavior, but it is a bit confusing to see the order
                  of the variables change).</div>
                <div><br>
                </div>
                <div style="text-align:center">* * *</div>
                <div><br>
                </div>
                <div>As a side-note: I've been chasing this bug for some
                  time, since it specially affected students using
                  Cuis-University (denotative objects are classes behind
                  the scenes, so all instance variables are class
                  instance variables). The bug was hard to find because
                  when you recompile the method (e.g. make any change
                  and recompile, or file it out and then file it in,
                  etc.), the bytecode is silently fixed.</div>
                <div><br>
                </div>
                <div>Cheers!</div>
                <div>Facu</div>
              </div>
              <br>
              <fieldset></fieldset>
            </blockquote>
            <pre cols="72">-- 
Juan Vuletich
<a href="http://www.cuis.st" target="_blank" moz-do-not-send="true">www.cuis.st</a>
<a href="http://github.com/jvuletich" target="_blank"
            moz-do-not-send="true">github.com/jvuletich</a>
<a href="http://researchgate.net/profile/Juan-Vuletich" target="_blank"
            moz-do-not-send="true">researchgate.net/profile/Juan-Vuletich</a>
<a href="http://independent.academia.edu/JuanVuletich" target="_blank"
            moz-do-not-send="true">independent.academia.edu/JuanVuletich</a>
<a href="http://patents.justia.com/inventor/juan-manuel-vuletich"
            target="_blank" moz-do-not-send="true">patents.justia.com/inventor/juan-manuel-vuletich</a></pre>
          </div>
          -- <br>
          Cuis-dev mailing list<br>
          <a href="mailto:Cuis-dev@lists.cuis.st" target="_blank"
            moz-do-not-send="true" class="moz-txt-link-freetext">Cuis-dev@lists.cuis.st</a><br>
          <a href="https://lists.cuis.st/mailman/listinfo/cuis-dev"
            rel="noreferrer" target="_blank" moz-do-not-send="true"
            class="moz-txt-link-freetext">https://lists.cuis.st/mailman/listinfo/cuis-dev</a><br>
        </blockquote>
      </div>
      <br>
      <fieldset class="moz-mime-attachment-header"></fieldset>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 
Juan Vuletich
<a class="moz-txt-link-abbreviated" href="http://www.cuis.st">www.cuis.st</a>
github.com/jvuletich
researchgate.net/profile/Juan-Vuletich
independent.academia.edu/JuanVuletich
patents.justia.com/inventor/juan-manuel-vuletich</pre>
  </body>
</html>