<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Fixed 2 and 3.</p>
    <p>- 2 was due to not handling block nodes properly when they didn't
      have any statements (data-flow analysis stripped the procedure
      completely clean since no result was set), hence an access
      violation occurred while accessing a node that was nil.<br>
    </p>
    <p>- 3 was a two-fold problem:</p>
    <ol>
      <li>The functiuon being ineligible was because a typeconv node
        couldn't be stripped out and so the final assignment tree wasn't
        in an expected format.  The analysis code now specifically
        permits this form of type conversion (convtype = tc_equal and
        identical resultdefs between the typeconv and the load nodes).</li>
      <li>The second problem was due to a small hack where implicit
        Result parameters were converted from var to out so data-flow
        analysis worked properly, but they weren't converted back to var
        parameters afterwards, causing an access violation elsewhere in
        the code.</li>
    </ol>
    <p>Merge request has been updated - I have also added two new tests
      based on your examples.  Thanks again Marģers.</p>
    <p>Kit<br>
    </p>
    <div class="moz-cite-prefix">On 28/06/2024 13:24, J. Gareth Moreton
      via fpc-devel wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:87c34547-8ff5-4c4f-be52-d52874962c3a@moreton-family.com">Hi
      Marģers,
      <br>
      <br>
      Thanks for the feedback!
      <br>
      <br>
      Assigning the results of pure functions to constants has not yet
      been developed.  I had planned to add it once the bulk of pure
      functions (i.e. the current merge request) had been approved since
      it requires some additional work (specifically what happens if the
      function is not actually pure or otherwise can't return a
      straightforward result).
      <br>
      <br>
      2 and 3 are definite bugs though.  The second case should at the
      very least make the function impure, while the third case should
      indeed not disqualify the function.  I'll see what I can do.
      Thanks again.
      <br>
      <br>
      Kit
      <br>
      <br>
      On 28/06/2024 09:35, Marģers . via fpc-devel wrote:
      <br>
      <blockquote type="cite">1. pure function value to constants
        <br>
        <br>
        function foo(i:longword):longword; pure;
        <br>
        begin
        <br>
          foo:=9;
        <br>
        end;
        <br>
        <br>
        const bar = foo( 8 );  //-- not allowed.. but i expect this to
        work!
        <br>
                 jar : longword = foo( 7 ); //-- and this as well
        <br>
        <br>
        <br>
        2. this does not end grasefully
        <br>
        <br>
        function foo (i:longword):shortstring; pure;
        <br>
        var s : shortstring;
        <br>
              n : longword;
        <br>
        begin
        <br>
          s:=''';
        <br>
          for n:=1 to i do s:=s +'a';
        <br>
          //-- not assing return value
        <br>
        end;
        <br>
        begin writeln(foo(9)); end.
        <br>
        <br>
        3.
        <br>
        function foo (i:longword):ansistring; pure;
        <br>
        var s : shortstring;
        <br>
              n : longword;
        <br>
        begin
        <br>
          s:=''';
        <br>
          for n:=1 to i do s:=s +'a';
        <br>
          foo:=s; //-- this makes function not pure, but why whould it!
        <br>
        end;
        <br>
        begin writeln(foo(9)); end.
        <br>
        <br>
        <br>
        _______________________________________________
        <br>
        fpc-devel maillist  -  <a class="moz-txt-link-abbreviated" href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>
        <br>
        <a class="moz-txt-link-freetext" href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>
        <br>
      </blockquote>
      <br>
    </blockquote>
  <div id="DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br /><table style="border-top: 1px solid #D3D4DE;"><tr><td style="width: 55px; padding-top: 13px;"><a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" target="_blank"><img src="https://s-install.avcdn.net/ipm/preview/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif" alt="" width="46" height="29" style="width: 46px; height: 29px;"/></a></td><td style="width: 470px; padding-top: 12px; color: #41424e; font-size: 13px; font-family: Arial, Helvetica, sans-serif; line-height: 18px;">Virus-free.<a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" target="_blank" style="color: #4453ea;">www.avast.com</a></td></tr></table><a href="#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" height="1"> </a></div></body>
</html>