... the const behavior seems like a bug to me.
It is not a bug, but a stumbling block if you have not read the documentation, which is clear.
For instance,
"Note that specifying const is a contract between the programmer and the compiler. It is the programmer who tells the compiler that the contents of the const parameter will not be changed when the routine is executed, it is not the compiler who tells the programmer that the parameter will not be changed. This is particularly important and visible when using refcounted types. For such types, the (invisible) incrementing and decrementing of any reference count is omitted when const is used. Doing so often allows the compiler to omit invisible try/finally frames for these routines.
As a side effect, the following code will produce not the expected output:
Var
S : String = ’Something’;
Procedure DoIt(Const T : String);
begin
S:=’Something else’;
Writeln(T);
end;
begin
DoIt(S);
end.
Will write
Something else
This behaviour is by design."
const is a hint to the compiler from the programmer, nothing more than that. Giving the compiler a false hint (as in this case) will most likely produce unexpected results. However, there are situations where giving a false hint to the compiler (declaring const, and then changing the const parameter) still "works".