* fix : do a for-in on a string variable using low(strvar) to high(strvar) so that zero based strings are handled correctly

+ added test
This commit is contained in:
Sven/Sarah Barth 2023-11-07 20:28:15 +01:00
parent 5205ce30f4
commit 68668c649e
2 changed files with 21 additions and 2 deletions
compiler
tests/webtbs

View File

@ -586,8 +586,8 @@ implementation
addstatement(loopbodystatement,hloopbody);
forloopnode:=cfornode.create(ctemprefnode.create(loopvar),
genintconstnode(1),
cinlinenode.create(in_length_x,false,ctemprefnode.create(stringvar)),
cinlinenode.createintern(in_low_x,false,ctemprefnode.create(stringvar)),
cinlinenode.create(in_high_x,false,ctemprefnode.create(stringvar)),
loopbody,
false);

19
tests/webtbs/tw40500.pp Normal file
View File

@ -0,0 +1,19 @@
program tw40500;
{$mode objfpc} {$h+} {$coperators+} {$zerobasedstrings+}
uses
SysUtils;
var
s: string;
c: char;
begin
s := '';
for c in string('share this to instantly die') do
if (c >= #32) and (c <= #127) then s += c else s += '#' + IntToStr(ord(c));
writeln(s);
if s <> 'share this to instantly die' then
Halt(1);
end.