<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div>
<div><br/>
Dear FPC developers,</div>
<div> </div>
<div>Since I am unable to provide a comment on bug report #33912 itself, I figured I had but one option to move the discussion here. Basically, I don't follow the reasoning that led to closing the report "as designed" out of several reasons. To put the situation in a nutshell, the following (condensed) program has some very unexpected runtime behaviour but the behaviour is deemed correct as of writing and according to #33912.</div>
<div> </div>
<div> </div>
<div>type Vector = array of integer;</div>
<div> </div>
<div>function DoSomething (len: longint): Vector; begin<br/>
SetLength (result,len); // whatever<br/>
end;</div>
<div><br/>
var A,B: Vector;<br/>
begin<br/>
A := DoSomething(3);<br/>
// changing A here will influence B below,<br/>
// which seems ok to some as<br/>
// "managed types are not initialized when<br/>
// calling DoSomething and this is documented</div>
<div> // - so anything goes and stop whining".<br/>
B := DoSomething(3);<br/>
end.</div>
<div><br/>
I strongly believe that the behaviour as currently implemented is wrong and here is why. </div>
<div>(1) When assigning "result" to A, refcount of result needs to go down and, hence, the local var needs to be freed/invalidated. (Result goes out of scope.)<br/>
(2a) Since the compiler takes care of managing the type (hence the name "managed type"), the compiler is responsible for a minimal initialization that is in d'accord with the semantics of the language.<br/>
(2b) The syntax makes it very clear that there never is anything passed into the function, that result is a "fresh" variable living only within the scope of the function, and that A and B are very different variables. Hence result cannot have some value of a managed type returned in a previous call, which went out of scope at the time of returing to some different variable.</div>
<div>(3) The behaviour is incompatible to Delphi (tested 10.2.3 vs. Lazarus 1.8.0). Delphi shows the expected behaviour of treating A and B as distinct.</div>
<div> </div>
<div>I hope this issue gets addressed, as I deem the current behaviour completely broken and also going totally against the spirit of Pascal, feeling much more like some very obscure behaviour I'd expect from some C compiler. Honestly speaking, I had started to use Lazarus/FPC couple of months ago to do some database driven app, connecting to salesforce etc. and I enjoyed the experience quite a lot. Discovering the handling of this issue, however, makes me wonder whether fpc aims to be a great Pascal compiler that does without bad surprises and very very hard to debug "documented" behaviour or not.</div>
<div> </div>
<div>Thanks for your consideration,<br/>
Willibald<br/>
</div>
</div></div></body></html>