Version was FPC3.20
The behavior is no problem, but I would expect it should simple to
implement a compiler warning, otherwise it is easy to create
very hard bugs to find. A newbie would not expect this to
fail.
I would against that "solution", as this is a code generator bug, i.e. by design it should not do so, but as we expected, so a warning should not be required in the first place.
Anyway, it's not difficult to find the cause. Using OP's program, I try seeing the difference between if the first element is 'project' and if it's 'projects', diff tells me this:
# [6] for name in ['project','customer','supplier'] do | # [6] for name in ['projects','customer','supplier'] do
movl _$STRINGLOOPTEST$_Ld1,%eax | movq _$STRINGLOOPTEST$_Ld1,%rax
movl %eax,24(%rsp) | movq %rax,24(%rsp)
movw _$STRINGLOOPTEST$_Ld1+4,%ax | movq _$STRINGLOOPTEST$_Ld2,%rax
movw %ax,28(%rsp) | movq %rax,32(%rsp)
movb _$STRINGLOOPTEST$_Ld1+6,%al | movq _$STRINGLOOPTEST$_Ld3,%rax
movb %al,30(%rsp) | movq %rax,40(%rsp)
movl _$STRINGLOOPTEST$_Ld2,%eax <
movl %eax,31(%rsp) <
movw _$STRINGLOOPTEST$_Ld2+4,%ax <
movw %ax,35(%rsp) <
movb _$STRINGLOOPTEST$_Ld2+6,%al <
movb %al,37(%rsp) <
movl _$STRINGLOOPTEST$_Ld3,%eax <
movl %eax,38(%rsp) <
movw _$STRINGLOOPTEST$_Ld3+4,%ax <
movw %ax,42(%rsp) <
movb _$STRINGLOOPTEST$_Ld3+6,%al <
movb %al,44(%rsp) <
movl 40(%rsp),%eax | movq 40(%rsp),%rax
movl %eax,16(%rsp) | movq %rax,16(%rsp)
movb 44(%rsp),%al <
movb %al,20(%rsp) <
movl $6,%edx | movl $7,%edx
imulq $7,%rax,%rax | leaq (%rsp,%rax,8),%rsi
leaq (%rsp,%rax),%rsi <
.ascii "project\000" | .ascii "projects\000"
The line after leaq before .ascii calls fpc_chararray_to_ansistr, but %edx which I suppose stores the char array length (tested by using 'projec' as first element, it then became $5), remains a constant. This makes fpc_chararray_to_ansistr always return the same length strings.